-
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
Top 7 Salesforce Trends For 2022
Every technology we know is updating itself rapidly. If you do not keep an eye on the new additions, you might miss some amazing benefits…
Syncing Articles from Zendesk Knowledge Base to Salesforce Knowledge – A Success Story
Customers need excellent support with minimal human interaction. That’s why they prefer self-service. And to keep customers hooked to your product, you need to give…
What is the Database.Stateful Interface in Batch Apex?
We know Salesforce has a powerful way to do bulk processing with Batch Apex. However, I rarely come across scenarios where Database.Stateful is needed. Batch…
Popular Salesforce Videos
An Introduction to Salesforce org Nonprofit Cloud
Did you know that over 30,000 nonprofit organizations use Salesforce? Salesforce.org’s premier product, NPSP, helps nonprofits drive greater impact by connecting everything they do. Learn…
Why Sinergify is best-of-breed Salesforce-Jira Connector
Salesforce and Jira Integration have been simplified with Sinergify. The product allows for seamless integration between both instances and offers numerous benefits including effective collaboration…
Top 3 Interview Tips | How To Land A Salesforce Job
In this video, brad discusses the TOP 3 ways to nail your interview and land a job as a Salesforce Professional. These tips apply to…