-
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
Top 6 Benefits of Salesforce QuickBooks Integration
QuickBooks is an essential accounting application that many businesses trust today. It allows accounting professionals to record transactions with ease and accuracy. Whether you're billing…
How to Improve Revenue with CPQ Software in 2023? | Salesforce CPQ
Creating sales is not a simple task. To develop familiarity and interest in a product, the sales team must exert additional effort in creating persuasive…
Why to Hire a Salesforce Partner Company for Salesforce Project?
While you can implement Salesforce on your own, hiring an outside Salesforce specialist is often the best way to ensure the project is completed on…
Popular Salesforce Videos
Tracking Member Engagement with Scoring and Dashboards
More than half of organizations with a member engagement plan reported that it helped them increase: Membership renewals by 51%. Attendance at events and webinars…
How to Delete Multiple Contacts at Once | Salesforce Tutorial
Do you need to delete a bunch of records? Don't want to delete records one by one? This video shows you several ways to delete…
BradForce Interview with special guest Jason Jung | Landing Your First Salesforce Job
In this video, I have a great conversation with Jason Jung. Jason landed his first Salesforce Job in the middle of a global pandemic. Listen…