-
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
Ultimate Guide: How to Import Your Salesforce Metadata into AbstraLinx
In the dynamic landscape of data management, the need for efficient and user-friendly tools has never been more critical. This article unveils AbstraLinx, a specialized…
Salesforce vs Hubspot: Which CRM is the Best Fit for Your Business Needs?
As companies grow and expand, managing customer relationships becomes a complex and challenging task. This is where customer relationship management (CRM) software comes into play.…
Spring ’23 New Release Update | All You Need to Know
Spring '23 features that align with the core admin responsibilities are: Release Highlights for Admins Salesforce Admins drive innovation with four core responsibilities: User Management,…
Popular Salesforce Videos
How To Use Salesforce Marketing Cloud Automation Studio
In this video, you will learn how to use Salesforce Marketing Cloud Automation Studio which will help in automating various processes. The following points will…
How does Salesforce Field Service Platform increase servicing revenue for your company
CRM Salesforce, along with its Field Service Lightning App, is drastically improving the field-force productivity in the industry. Built on the Salesforce Service Cloud, it…
How to Switch your Career from Being an HR or a Recruiter to a Salesforce Developer/QA or a BA
In this video, Shrey has answered one of the most frequently asked questions about how someone who is working in HR or as a Recruiter…