-
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
How to Boost Your Business with a Salesforce Partner Company?
Are you looking to take your business to the next level? If so, consider leveraging the power of Salesforce, one of the world's leading customer…
5 Features Salesforce LMS Integration Brings to the Table
Introduction In this competitive market, organizations strive to keep their business ahead to gain a competitive edge. Every organization’s growth and profitability rely on the…
Bric Enterprise - Customised Business Card Management Software
Business card scanners / APPS are an important tool for most organizations to effectively manage customer contacts, leads etc. The requirement may vary from one company to…
Popular Salesforce Videos
Salesforce JMS Integration Using MuleSoft | Salesforce Tutorial
Salesforce JMS Integration. In this video, the following points will be covered - 1. Introduction Learn how to use queues to integrate data in Salesforce.…
FlexDeploy for Salesforce
FlexDeploy can improve your enterprise software development, operations, and release processes using out-of-the-box support for Salesforce. See how FlexDeploy supports org-based development, source-driven development, or…
Salesforce and Slack: Success from Anywhere - Your Digital HQ
Welcome to Success from Anywhere: Your Digital HQ. Join our Slack-First Customer 360 event to find out more. Register now: https://www.salesforce.com/events-master/digital-hq/ Success Anywhere means coming…