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 

creates two identical Opportunities when ever an Account is created

Write a trigger that creates two identical Opportunities when ever an Account is created.Make sure both opportunities are associates with the Account.
Use any values for the fields on the opportunities
Just make sure to use variables when populating the fields of each opportunity to make sure they are identical.
 
v varaprasadv varaprasad
Hi,

Please check once below sample code:
 
trigger CreateOpps on Account (After insert) {
    list<opportunity> lstOpps = new list<opportunity>();
    
    for(account acc : trigger.new){
         //1st opp
        opportunity op = new opportunity();
        op.name = acc.name;
        //Add reaming fields
        
        lstOpps.add(op);
       
        //2nd  opp
        opportunity op1 = new opportunity();
        op1.name = acc.name;
        //Add reaming fields
        
        lstOpps.add(op1);
        
    }
  
    if(lstOpps != null){
        insert lstOpps;
    }
    
    

}

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.


Thanks
Varaprasad
Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
 
Gateway Bikes Group4Gateway Bikes Group4
Thanks & it worked