-
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
Get Picklist Values in Salesforce Lightning Component From a Common Apex Function
See below the code example to get Picklist Values in Salesforce Lightning Component from a Common Apex Function: CommonPicklist.cmp <aura:component controller="CommonPicklistController"> <aura:attribute name="ObjectName" type="String" default="Opportunity"…
Salesforce Consulting Services: Roles & Responsibilities
Introduction A leading business expert has correctly said- “Salesforce is a wonderful skill which if properly harnessed; can open the doors of fortune at your…
Develop in Production: Insane or Inspired?
Accelerating implementation We all know the benefits of accelerating and streamlining the release cycle; the business is more agile and reduced development effort. But there…
Popular Salesforce Videos
Salesforce Commerce Cloud Vs Shopify – Which One Is Better
If you own an e-commerce business in today's time, it becomes imperative to have a right-fit platform that helps you stand out from your competition…
Creating A Chart in Einstein Analytics
In this video, you will learn how to create a new dashboard, and add a chart. You will also learn how to select the dataset…
Running a New Report in Salesforce
After logging into Salesforce, Go to the reporting section by clicking on the Reports tab at the top of the page, Click on the New…