-
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
Using CRON Expression in Salesforce
Hello to all the salesforce developers, here in this blog I am covering a very crucial topic that we all use in our coding skills…
What are Global Picklist or Picklist Value Sets in Salesforce
A worldwide Picklist infers a picklist which you'll be able to access for all Salesforce objects. Because it was on the off chance simply making…
Types of Salesforce Sales Cloud Services
Modern sales teams need more than spreadsheets, follow-ups, and disconnected tools. They need a system that helps them sell smarter, close faster, and scale confidently.…
Popular Salesforce Videos
How to Add 'Add Campaign' Button to the Report Type | Salesforce Tutorial
Do you want to know How to Add 'Add Campaign' Button to the Report Type in Salesforce? In this session, Distinguished Architect Iman Maghroori shows…
Salesforce CPQ: Fixing Percent of Total Calculations for Amended Quotes
Salesforce users looking to enhance their product-quoting processes can take advantage of Salesforce Configure, Price, Quote Software, or CPQ. Some features require the use of…
Skill Based Routing with Apex/Flows in Salesforce
This video is the sequel to the omnichannel Salesforce tutorial (LINK) In this video, we will cover: 1. What is Skill-based routing 2. Why is…