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
nagarjuna gurajanagarjuna guraja 

Need Trigger on Account Opportunity

Hello Everyone,
 I need Trigger. Please help anyone
Write a trigger such that whenever Account record is created, Automatically Opportunity name should also be created.
Thanks in advance.
VinayVinay (Salesforce Developers) 
Hi Nagarjuna,

Try below sample code.
trigger createopp on Account (after insert) {
    List<Opportunity> opplt=new List<Opportunity>();  
    for(Account a:Trigger.new)
    {
        Opportunity opp=new Opportunity();
        opp.AccountId=a.id;
        opp.Name='Account creation';
        opp.StageName='Prospecting';
        opp.CloseDate=Date.toDay();
        opplt.add(opp);
    }
    insert opplt;
}

Please mark as Best Answer if above information was helpful.

Thanks,