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
HelloSanHelloSan 

I need apex trigger code when account is inserted opportunity must be inserted similarly for updation and deletion,how can i achieve this

Vijaya Kumar RegantiVijaya Kumar Reganti
Hi,

You can just try with the following code snippet.

trigger MyTrigger on Account(after insert){
     list<contact> lst = new list<contact>();
     for(account a: trigger.new){
     contact c = new contact(lastName = a. name,phone = a.phone);
     lst.add(c);
  }
  insert lst;
}


Thanks,
Vijay

 
Ankit Maini.Ankit Maini.
trigger Account_trigger on Account (after insert) {

    /** EXAMPLE OF HOW TO -- NOT -- WRITE A BULK TRIGGER **/

    // iterate over the list of records being processed in the trigger 
 
    List<Opportunity> opp = new List<Opportunity>();
    for (Account a : Trigger.new) {
    o.Account = a.Id;
    o.Name = 'opp 1';
    o.CloseDate = Date.today();
    o.stageName = 'stage1';
    opp.add(o);

}

insert opp;
}