-
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
Einstein Activity Capture | The Ultimate Guide
Einstein Activity Capture Salesforce Einstein Activity Capture is a powerful tool that enables businesses to keep track of their customer interactions and activities. It is…
What are the Must Have Salesforce Integrations For Businesses in 2023?
In this day and age of ever-growing business needs, no one can deny that the ability to keep systems running smoothly is absolutely crucial. That's…
No Code ScheduleOnce and Salesforce Integration
ScheduleOnce is a cloud-based scheduling service that enables businesses of all sizes to schedule and manage user engagement with their users and prospects. Users can…
Popular Salesforce Videos
70 Salesforce Interview Questions for the Beginners
First of all, How it is different from the other Salesforce Interview questions videos? Well, We have divided the questions into categories so that you…
How to Send a Pardot Email with Multiple Line Items | Salesforce
It is impossible to send a Pardot email that has a list of related records… or is it? In this session, Adam Erstelle uncovers strategies…
Salesforce Sales Engagement Mastery: Proven Strategies for Efficiency and Success
Salesforce stands as a cloud-based customer relationship management (CRM) software capable of revolutionizing sales procedures and enhancing the efficiency of internal sales representatives. This dynamic…