I'm working on a requirement as follows: Whenever an Opportunity is created or edited, its custom region picklists (Region__c) should be overwritten with the Account region picklists (Region__c).
Trying to develop a trigger that would satisfy this requirement.
Whenever an Opportunity is created or edited, check to see if any of the custom Region__c picklists are NULL. If any are NULL, overwrite all picklist fields with corresponding data from the Account object.here's what I have so far:
trigger UpdateOpptyPicklists on Opportunity(Before Insert, Before Update) {
for(Opportunity o: Trigger.new){
Account a = [select id,Region__c,Area__c, Division__c from Account where Id=:o.AccountId];
if(o.Region__c == NULL || o.Area__c == NULL || o.Division__c == NULL){
o.Region__c=a.Region__c;
o.Area__c = a.Area__c;
o.Division__c=a.Division__c;
}
}
}
How can I bulkify this trigger