-
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
Event Management in Salesforce in 2024
How to Build a Robust Event Management System on Salesforce? Organizing events is a strategic business initiative with multifaceted benefits. From expanding professional networks to…
Maintaining Org Security with the Salesforce Health Check
You likely fell in love with Salesforce because of its flexibility. With its 'no-code' customizability and extensive range of third-party apps, the platform is endlessly…
Learn Salesforce Einstein – Chapter 5 (What is DataSet?)
What is DataSet? Data set is the collection of data to train the machine to predict. Let's understand this in the real world example. Assume…
Popular Salesforce Videos
Salesforce Summer ’22 Release | Flow Enhancement of Summer 22 Release with Example
Exceed your business goals with the Summer ’22 release by seamlessly integrating your data, finding meaningful insights, and building lifelong customer relationships. How to Use…
Enhance Not Divest your Investment in Salesforce
Here in a short Video Blog, Ian Moyse, Natterbox Sales Director and Sales Director of the year winner (Institute of Sales Management) talks to how…
360 SMS App Demo
360 SMS App is considered to be the most reliable Salesforce SMS App. This App is listed on the AppExchange from the name "360 SMS…