Skip to main content
Hi ,

I have written a simple after insert trigger on Account such that for every new Account created, a new related Opportunity is created.

But the trigger is not getting invoked.Any ideas why this may be happening

trigger CreateNewAccountOpportunity on Account (after insert) {

    List<Opportunity> oppList = new List<Opportunity>();

    for(Account acc : Trigger.new){

        Opportunity opp = new Opportunity();

        opp.Name = acc.Name;

        opp.StageName = 'Proposal';

        opp.CloseDate = System.today() + 30;

        oppList.add(opp);

    }

    System.debug('@@@---->'+Trigger.new);

       System.debug('oppList---->'+oppList); 

    

    if(oppList.isEmpty() == false){

        Database.insert(oppList);

    }

}
3 answers
  1. Jun 9, 2019, 6:38 AM
    Hi Abhilash,

    Firstly make sure your trigger is active.

    Secondly,  Add the below line in the opporttunity creation block.

    opp.Id = acc.Id;
0/9000