-
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
How to Hire Salesforce CPQ Developer for Business Success
In the competitive world of B2B sales, speed and accuracy are the dual engines of growth. However, as product catalogs grow and pricing structures become…
Certified Salesforce Consulting Partner – A Game Changer for Businesses
In today’s digital world, businesses rely on Customer Relationship Management (CRM) platforms like Salesforce to streamline operations, enhance customer engagement, and drive sales growth. However,…
Your Complete Guide to Salesforce Nonprofit Cloud
Aside from Sales Cloud, Service Cloud, and Marketing Cloud, Salesforce also has a product designed specifically for nonprofit organizations – Nonprofit Cloud. Salesforce’s Nonprofit Cloud…
Popular Salesforce Videos
What is Workflow Rule in Salesforce | Salesforce Interview Questions and Answers
What is Workflow Rule in Salesforce | Salesforce Interview Questions and Answers
How to Connect to External Data | Salesforce
An external data source specifies how to access an external system. Salesforce Connect uses external data sources to access data that's stored outside your Salesforce…
Introduction to Salesforce Commerce Cloud for Developers
Commerce Cloud powers e-commerce for many of the world's leading brands and it represents a great opportunity for developers around the world. Join us to…