• kavya T 5
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi All,
   I am new to Salesforce and i tried test class for below trigger but i got code coverage only 35%.

whenever An Account is created with number_of_Employees__c(custom field)>99 create 10 opportunities for Account.

trigger CreateTenOpportunity on Account (after insert)
{
    List<Opportunity> oppList=new List<Opportunity>();
    for(Account acc:trigger.new)
    {
        if(acc.Number_of_Employees__c>99)
        {
            for(integer i=0;i<10;i++)
            {
              opportunity opp=new opportunity();
              opp.Name=acc.Name+ i;
              opp.AccountId=acc.Id;
              opp.StageName='Prospecting';
              opp.CloseDate=Date.today()+15;
              oppList.add(opp);  
            }
        }
    }
    if(oppList.size()!=0){
        insert oppList;
    }
}

 
Hi All,
   I am new to Salesforce and i tried test class for below trigger but i got code coverage only 35%.

whenever An Account is created with number_of_Employees__c(custom field)>99 create 10 opportunities for Account.

trigger CreateTenOpportunity on Account (after insert)
{
    List<Opportunity> oppList=new List<Opportunity>();
    for(Account acc:trigger.new)
    {
        if(acc.Number_of_Employees__c>99)
        {
            for(integer i=0;i<10;i++)
            {
              opportunity opp=new opportunity();
              opp.Name=acc.Name+ i;
              opp.AccountId=acc.Id;
              opp.StageName='Prospecting';
              opp.CloseDate=Date.today()+15;
              oppList.add(opp);  
            }
        }
    }
    if(oppList.size()!=0){
        insert oppList;
    }
}