-
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
Use Salesforce Lightning Component in Visualforce Page
In winter ‘16 a new and powerful feature was introduced which allows you to implement your Salesforce Lightning Component in Visualforce pages. There are three…
Salesforce Customization vs. Configuration: Choosing the Right Approach
Unlocking the full potential of Salesforce can be a game-changer for your business. According to the Salesforce Relationship Survey, implementing Salesforce can supercharge your deal…
How Hiring a Salesforce Implementation Partner Could Benefit the Healthcare Sector
Digitalization of healthcare is a complex task due to the sector's unique challenges, such as handling various types of data and interdependent roles. Salesforce implementation…
Popular Salesforce Videos
Automate Simple Business Processes with Process Builder | Salesforce Trailhead
In this video, we working on the Trailhead challenge Lightning Flow unit Automate Simple Business Processes with Process Builder where a lot of trailblazers face…
Get Started with Salesforce for Recruitment and Admissions: Admissions and Onbaording
This webinar is designed for Salesforce admins and users who work in Recruitment and Admissions. We will cover all you need to know about using…
TrailheaDX 2020 Opening Film | Salesforce
Now more than ever, Trailblazers are using the Salesforce Platform from anywhere in the world to collaborate, innovate, make a change, and build a brighter…