-
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

Advancing the Salesforce's Email-to-Case with Email to Case Advance
Intensifying Subscription Economy & Retaining Customers I am not going to go back to the books to explain what ‘Subscription Economy’ is. We all are…

How to Use Map In Lightning Component?
For using the map in the lightning component, we need to define the attribute of the type map to hold key-value pairs. In this blog,…

What are the Functions, Benefits, and User Reviews of Salesforce? | Salesforce 101
No doubt you've heard a lot about Salesforce CRM lately. But Salesforce seems to be something huge, something confusing, and turns out that it's not…
Popular Salesforce Videos
See what amazing things Cauzali can add to your Salesforce solution - without code
Use Cauzali to add functionality to your Salesforce community solution. In this video, we have a focus on Salesforce Financial Service Cloud, but Cauzali works…
Keep Salesforce Field Values Clean in Summer 20 in less than 10 minutes - Salesforce Break
Keep Salesforce Mobile Phone field clean by stripping out the ()- characters from the user entry. Ensuring data quality is a challenge for every Salesforce…
Salesforce Stock CRM Huge News!
Why is Salesforce Stock CRM Stock going UP? Is Salesforce stock a buy? Should I buy CRM Stock? Is Salesforce stock a good investment? In…