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
vivek singh08481200707119766vivek singh08481200707119766 

I want make a trigger in opportunity my requirment is make a custom object invoice when stage is is close won then trigger working please help me

hitesh90hitesh90

hello vivek,


see below sample example for your requirement.

Apex Trigger:

 

trigger trgInsertInvoice on Opportunity (after update) {
    List<Invoice__c> lstInvoice = new List<Invoice__c>();
    Invoice__c objInvoice;
    for(Opportunity opp: trigger.new){
        if(opp.StageName == 'Closed Won' && trigger.oldmap.get(opp.id).StageName != 'Closed Won'){
            objInvoice = new Invoice__c();
            objInvoice.Name = 'Test Invoice';
            objInvoice.Opportunity__c = opp.id;            
            lstInvoice.add(objInvoice);
        }
    }
    if(lstInvoice.size() > 0){
        insert lstInvoice;
    }    
}


Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/