-
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
Shaping Customer Experience in Banking with Salesforce
Just like any other industry, banking these days faces an urgent need to reimagine itself and work on achieving new opportunities for growth. The need…
An Ultimate Guide to Salesforce Workflow Automation
Workflow automation is the use of software or other technologies to facilitate and streamline complex business processes. Typically, these processes involve a large number of…
Single or Multi-Org - What is your Salesforce Architecture?
While setting up a Salesforce Architecture or assessing the performance of an existing org, the most perplexing question that haunts anyone is to decide between…
Popular Salesforce Videos
Dreamforce to You London 2019: Round-up Video!
Great to contribute to the Salesforce #Dreamforcetoyou event as a Cloud Social Influencer and here is my roundup.
Developer Preview Live - Release Readiness Live, Winter '22 | Salesforce
The Winter ’22 release is packed full of features to help developers solve key business problems fast. Join us to learn from Product Managers and…
How to Find More Prospects, Win More Deals, and Keep Customer Happy with Salesforce Essentials
Watch this video to learn how to minimize busy work and empower your sales and support teams to spend more time closing deals and engaging…