function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gateway Bikes Group4Gateway Bikes Group4 

Identical opportunity with Conditional statement

/***ERROR Message
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ven.IdenticalOpp9 caused an unexpected exception, contact your administrator: ven.IdenticalOpp9: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ven.LeadingCompetitor: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.ven.LeadingCompetitor: line 34, column 1: []: Trigger.ven.IdenticalOpp9: line 32, column 1

*/
/*Write a trigger that creates 10 identical Opportunities whenever an Account with more than 99 employees is created. 
Make sure all Opportunities are associated with the Account. 
Use any values for the fields on the Opportunities*/

  trigger IdenticalOpp9 on Account(after insert){
 
      List<Opportunity> opplist= new List<Opportunity>();

     
        for(Account ac:Trigger.new){
        
               if(ac.NumberOfEmployees>99){
       
                     for(integer count=0;count<10;count++){
       
                        Opportunity opp=new Opportunity();
                          opp.AccountId=ac.id;
                               opp.Name='Created from account';
                          opp.StageName='Prospecting';
                          opp.CloseDate=Date.toDay();
                          opplist.add(opp);
                            }
                      }
             else{
             }
         }
       if(opplist!=null){
       insert opplist;

 }
 
}
Paul S.Paul S.
Whatever the issue is, it's in the LeadingCompetitor trigger...can you post that?