-
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
Meet Einstein GPT, the first generative AI for CRM
Since its release in November 2022, Chat GPT has become a buzzword - over a million people signed up to use it in just five…
Things You Need to Consider While Integrating WordPress and Salesforce
WordPress and Salesforce are no less than a match made in heaven. When you go for a WordPress Salesforce Integration (WordPress website with Salesforce as…
Commonly Made Mistakes in Salesforce Integration and How One Can Avoid Them
Hey you all, Bienvenue to my blog which is going to tell you about Integration and what few common mistakes occur at the time of…
Popular Salesforce Videos
Salesforce Lightning Training - Creating Hello World Lightning Component
Data Loader is a utility to perform bulk database operation. Recently Salesforce has changed the way data loaders need to be install. I explain end…
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…
Salesforce Grid Component Modernization with Webix Widgets
Take a break and watch a short video about how we modernized the Salesforce Grid component with Webix.