You need to sign in to do that
Don't have an account?
SambitNayak
Trigger on Contact to populate a field based on a condition
Hi,
I need a before Trigger on Contact that will update my Job grade field based on what value I enter for Job Code.
For e.g: If I create a contact with name : John Smith and Job Code =101, the trigger will search the Job Code Object with Job Code =101 and return the corresponding Job Grade for that --- And populate my Job Grade field on the Contact object.
Thanks.
I need a before Trigger on Contact that will update my Job grade field based on what value I enter for Job Code.
For e.g: If I create a contact with name : John Smith and Job Code =101, the trigger will search the Job Code Object with Job Code =101 and return the corresponding Job Grade for that --- And populate my Job Grade field on the Contact object.
Thanks.
for (Contact con:contList){
//When NULL Job Code is entered
if(con.Job_Code__c==NULL){
con.Salary_Job_Grade__c=NULL;
//contsToUpdate.add(con);
}
//When Job Code is not NULL
else{
Job_Code__c jc =[SELECT Salary_Job_Grade__c FROM Job_Code__c
WHERE Name =: con.Job_Code__c];
//system.debug(jc);
con.Salary_Job_Grade__c = jc.Salary_Job_Grade__c;
//contsToUpdate.add(con);
}
}
I tried this code but I am getting the 18 digit ID on the field rather that the actual value.
Try Below Code Please Mark It As Best Answer If It Helps
ThankYou!
I want to display an error if the job code entered is incorrect.
i.e: My code should be like:
if(Not Exists job_code__c){
con.addError('Please enter a correct Job Code')
}
i've Already Added The The Error Condition In My Code Above Please Close Your Query By Marking It As Best Answer If It Helps. So it Also Helps Others In Future
ThankYou!