-
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

Lightning App Manager in Salesforce - All you Need to Know
Lightning App In Salesforce An app is a group of components that work together to accomplish a certain task. With Lightning Experience, your users can…

Salesforce Editions - Keys for a Successful Selection
If you have already decided to adopt Salesforce CRM, you may find yourself in the dilemma of choosing which of its editions is more suitable.…

Types of Report Formats in Salesforce - All You Need to Know
What are the Report Formats in Salesforce? A Salesforce report is a list of information produced dependent on predefined standards. They can be displayed in…
Popular Salesforce Videos
When to Use Apex? | Flows of Action in Apex | Learn Salesforce Development
In this Video Shrey explained When to use Apex and Flows of Action in APEX. Let's Learn the End User and Developer action (Flows of…
Salesforce for Marketing
Learn how to bring marketing and engagement together. Salesforce Marketing Cloud helps you connect marketing, sales, service, and more on a single platform. Marketers get…
Ask Me Anything with Salesforce Developers | Lightning Web Components
Join experts Mohith Shrivastava and Greg Whitworth for our monthly feature Ask Me Anything! This 1-hour session on Lightning Web Components is your chance to…