New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Sunday, 5 August 2012

Whenever Opportunity stagename fieldset to 'Closed Won', a new record has created in patient object


trigger newpatient on Opportunity (after update) {
    Map<Id,Patient__c> patients = new Map<Id,Patient__c>();
    for(Integer i=0;i<Trigger.new.size();i++) {
        if(Trigger.new[i].StageName != Trigger.old[i].StageName && 
Trigger.New[i].StageName == 'Closed Won') {
            Patient__c p = new Patient__c(name='p101',Patient_Name__c='srinu',
Country__c='India',DOB__c=Date.valueOf('1987-07-18'),Opportunity__c=Trigger.new[i].id);
            patients.put(p.id,p);            
            }            
        }
        insert patients.values();
    }
 
Reference:
Click Here 

No comments:

Post a Comment

Labels