-
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
Bulk Scanning of Business Cards...
Accurate transcription of cards from any source Capturing business cards one by one on a mobile business card scanner or a device card scanner can be…
Email Service-Inserting Data in Salesforce using Email Attachment
Force.com provides us powerful and secure functionality for sending and receiving emails. We can execute our apex logic whenever we receive an email. By using…
Jira - Salesforce Integration: Why You Should Use a No-code Integration Platform?
Workflow automation, enhanced performance, and high availability are three of the most vital components of every successful modern-day enterprise. The ability to track valuable performance…
Popular Salesforce Videos
Custom Aura Feed Component | forceChatter:feed | Chatter in #Salesforce | Salesforce Tutorials
In this vlog I will create a custom aura feed component with two picklists to select Group and then based on the Group selection, select…
Duplicate Management In Salesforce | Duplicate Rule and Matching Rule
Learn how to work with duplicate rules and duplicate records in Salesforce. This video will cover the following points - 1. Matching Rule (1:20) Get…
Understanding Future Method | Difference Between Asynchronous and Synchronous Apex in Salesforce
In this video, Shrey explained Synchronous Apex and Asynchronous Apex in a simple way. He also explained the importance of the Future method in Salesforce.…