-
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
A complete list of Salesforce Events & Conferences for fall/winter 2018 – Part 2
What are industry’s Top Salesforce conferences and events heading to North America in the upcoming months? Let’s cut to the chase – here’s a list…
Top 10 Salesforce Winter ’21 Features for Pardot That Will Enhance your B2B Experience
Welcome back to our Salesforce Winter ’21 review series. This time, we are excited to tell you more about the Pardot winter release notes. We here at DemandBlue,…
Why Businesses Struggle to Choose Between Salesforce and Odoo (And How to Decide)
Choosing the right business platform is not always as simple as comparing features and prices. For many growing companies, the decision comes down to two…
Popular Salesforce Videos
A Beginner's Guide to Getting Started with Salesforce APIs Using Postman
A Beginner's Guide to Getting Started with Salesforce APIs Using Postman - Create Connected Apps in Salesforce - Introducing Postman - Connect to Salesforce from…
How to Automate Business Processes in Salesforce CRM | Salesforce Flow Explained
Want to streamline your business processes without diving into complex coding? In this video, Kirill, an AQA engineer and certified Process Automation Professional at ENWAY,…
How to Become a Salesforce Developer? No Programming Experience Needed
Salesforce Developer has once again been named one of the world's best jobs. In a list of 25 job roles, Salesforce was the only company…