-
My test class showing 0% code coverage in Salesforce?
I have to make trigger on opportunity whenever new opp is created create a post on account.
my trigger
trigger postOnAcc on Opportunity (after insert) {
List<FeedItem> posts = new List<FeedItem>(); //create a list to hold post
List<Id> oppList=new List<Id>(); //create a list to hold new opportunity
for(Opportunity o:Trigger.new) //Iterate for loop on new opportunity
{
oppList.add(o.AccountId); //add opportunity account id in opportunity list
}
for(Opportunity opp: [Select id,name ,AccountId from Opportunity where AccountId in:oppList]) //
{if(opp.AccountId != null){
FeedItem post = new FeedItem();
Post.ParentId = opp.AccountId;
post.body = 'New Opportunity is created with Opportunity Id - '+opp.Id + ' and Opportunity name is equal to - '+opp.Name;
posts.add(post); //add this post in posts List}
}
insert posts;
}my test class
@istest
private class testclass {
static testmethod void testclass()
{
Account a=new Account();
a.Name='AK';
insert a;Opportunity o=new opportunity();
o.Name='AJ';
o.AccountId=a.Id;
insert o;FeedItem post = new FeedItem();
Post.ParentId = o.AccountId;
post.body = 'New Opportunity is created with Opportunity Id - '+o.Id + ' and Opportunity name is equal to - '+o.Name;
insert post;}
}
Log In to reply.
Popular Salesforce Blogs
Value of Salesforce in Small and Medium Business
Speed is the quintessence of the business world. That is valid for almost every part of our business, yet it's particularly valid for innovation and…
Salesforce Administration Services: Why Every Business Needs Them in Today's Competitive Landscape
In today's fast-paced and highly competitive business landscape, companies are constantly seeking ways to streamline their operations, improve customer engagement, and drive revenue growth. Salesforce,…
How to Improve Your Customer Service with Salesforce Workflow Automation
Workflow automation drives service agents’ productivity due to quicker and more effective case resolution, which can’t but lead to better customer service quality and happier…
Popular Salesforce Videos
Explore Record Triggered Flow | Learn Salesforce Lightning Flows | Flow Builder Videos
Creating or updating a record can trigger an auto-launched flow to make additional updates to that record before it's saved to the database. A record-triggered…
Salesforce Lightning Development Tutorial - Lightning Components in Visualforce
Salesforce Lightning Custom Component Development Tutorial for Beginners Learn how to embed lightning components in a Visualforce page. 3 Steps Add apex:includeLightning tag in your…
Introducing Salesforce Experience Cloud LWR Sites | Lightning Web Runtime
In the first episode of this series, we'll walk you through what the Build-Your-Own (BYO) LWR template is. Based on our new sample app "AZ…