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