-
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
Federated Authentication Using SAML to Log in to Salesforce Org
Federated Authentication is one of the SSO(Single Sign On) Methods that uses SAML(Security Assertion Markup Language) assertion sent to the Salesforce endpoint and if everything…
How Can CRM Solutions Help to Build Your Brand | Salesforce
This is an undeniable fact that in today’s technologically progressive era, the business market is extremely competing. To survive successfully in such a vying business…
Send Salesforce Data for E-sign with Webmerge to Docusign
Hello All, here’s another Blog that helps Salesforce Users to send their data in the form of a document for Electronic Signature. So my blog describes…
Popular Salesforce Videos
Survival Kit for Beginner Salesforce Developers - 1
Are you a developer just starting out with Salesforce? Are you an admin looking to get into development? Join us to learn a few easy,…
Similarity and Difference Between SFRA and PWA | Which One to Choose? | Salesforce
Choosing SFCC as the platform necessitates a major decision: on what architecture will your channels be based? When learning about Salesforce B2C Commerce Cloud, you'll…
AMPscript Math Functions - Salesforce Marketing Cloud Functions in 5 minutes
Cameron Robert steps through how to use the AMPscript Math Functions in Salesforce Marketing Cloud. Key Moments: Introduction to AMPscript Math Functions (0:00) Add, Subtract,…