-
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
Custom Manufacturing Software Development: A Complete Guide for Manufacturers
Manufacturing businesses operate in an increasingly connected environment where production efficiency, product quality, inventory management, and supply chain coordination influence performance. Disconnected systems, spreadsheets, and…
Salesforce Classic to Lightning Migration: Benefits and Best Practices
Salesforce is a comprehensive CRM platform that delivers almost everything needed to manage business operations efficiently. It is a powerful toolset that enables top-level management…
Popular Salesforce Videos
Salesforce Communities: 5 Powerful Ways to Drive Growth
Salesforce Communities are brand spaces designed specifically for Salesforce customers to connect with the community outside their org (i.e., employees, partners, and customers) and collaborate…
A Must-Have for Admins: Salesforce Profiles, Permission Sets, and Roles Explained
Keeping your data safe and organized is a must-have. Luckily, Salesforce provides all the tools to help administrators control who can see and do what.…
Salesforce Marketing Cloud Automation Studio
Automation Studio is a Marketing Cloud application used to execute multi-step marketing and data management activities on an immediate, triggered, or scheduled basis. Use Automation…