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
vodnuravodnura 

Update field using trigger

I am trying out to implement a trigger, which will auto fill lookup fields based on a prticular field. Here is my code. can achieve this using workflow but wanted to know how it works with trigger. 

 

trigger trigger2 on Opportunity (before insert,before update) {

for(Opportunity Oppp : trigger.new){

if(Oppp.Recruiter__c =='A') // lookup field

{

Oppp.Director__c = 'B'; //lookup field

}


}

}

 

 

Thanks-

VODNURA

MJ Kahn / OpFocusMJ Kahn / OpFocus

I assume that Oppp.Recruiter__c and Director__c are your lookup fields. If so, note that they contains an Id value, not a String value like the name of the record you're looking up to. So you'll need to compare them to some other Id field, or store an Id value in them, not a String value.

 

Hopefully, that will help you get started with your trigger. If not, please post more details, including your modified code.