-
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
Low-Code vs. Pro-Code: Choosing the Right Approach on Salesforce Platform
Low-code and pro-code development models represent two powerful ways to deliver solutions on the Salesforce platform. As organizations accelerate digital innovation, the question of which…
Salesforce Commerce Cloud for E-Commerce
What Is Commerce Cloud? Commerce Cloud is one of the eight product clouds that make up the Salesforce Intelligent Customer Success Platform. Along with Sales…
Different Types of Salesforce Cloud And Their Features
The Salesforce cloud is a powerful, and comprehensive online platform designed to let companies of any size scale up and run their business easier, better,…
Popular Salesforce Videos
What is Apex? | Way to become a Salesforce Developer | Salesforce Development Tutorials
This video will provide you a complete path to become a Salesforce Developer. It includes very important and beneficial topics like Apex, Visualforce, Lightning. …
Highlights of the Salesforce Winter '22 Release for Nonprofits
The video includes both Winter ‘22 Salesforce Platform updates and Nonprofit Cloud tools. Chapters: 0:00 General Salesforce.com Platform Updates 8:13 Salesforce.com Release for Fundraising and…
4 Myths About Salesforce
Salesforce is a platform that helps businesses track the journey their customers take. It can help you effectively track and monitor your marketing and sales…