You need to sign in to do that
Don't have an account?

Need Trigger Help please!
Hello All!! I need some guidence with a trigger or class. I'm new to developing in general so I was hoping that some of the fantastic experts here could help me out. Here's the deal:
I have a custom object called 'SIC Codes' that has a code as the Name and 4 fields that are simply a 'yes' or 'no' text field. So a record would look like this:
Name: 1234
Description__c = 'doctors'
WC__c = yes
BOP__c no
GA__c = yes
GL__c = no
Now, on the Lead record I have a description text field that will match a SIC CODE record's description. So a lead may will have a description field that will say 'doctors'. The lead also has 4 text fields that match the fields above on the custom object's record.
What I am trying to do is say "If a lead comes in with a description that matches a description on the custom object, copy the values of the 4 custom fields to the lead record with those same custom fields. The result would be that the lead's field values for WC__c, BOP__c, ect... will match the 'yes' or 'no' from the record on the custom object that matches that description.
Now, i have a lead handler where I will put this trigger and call a class that will do all the work. I'm kind of overwhelmed and don't know how to get started. Any adivce or guidence would be increcible!
Thanks so much!
I have a custom object called 'SIC Codes' that has a code as the Name and 4 fields that are simply a 'yes' or 'no' text field. So a record would look like this:
Name: 1234
Description__c = 'doctors'
WC__c = yes
BOP__c no
GA__c = yes
GL__c = no
Now, on the Lead record I have a description text field that will match a SIC CODE record's description. So a lead may will have a description field that will say 'doctors'. The lead also has 4 text fields that match the fields above on the custom object's record.
What I am trying to do is say "If a lead comes in with a description that matches a description on the custom object, copy the values of the 4 custom fields to the lead record with those same custom fields. The result would be that the lead's field values for WC__c, BOP__c, ect... will match the 'yes' or 'no' from the record on the custom object that matches that description.
Now, i have a lead handler where I will put this trigger and call a class that will do all the work. I'm kind of overwhelmed and don't know how to get started. Any adivce or guidence would be increcible!
Thanks so much!
A Small Change Please Try Below One.
All Answers
Assuming that You are having Single SIC_Codes__c Record With Unique Description
Please try below code and update field accordingly. Please try it and let me know if you are facing any issue.
Thanks
A Small Change Please Try Below One.
duplicate value found: <unknown> duplicates value on record with id: <unknown>
trigger LeadTrigger on Lead (before insert) {
string sicDesc;
for(Lead l : Trigger.new){
sicDesc = l.SIC_Code_Description__c;
}
Map<String,VRNA__SIC_NAICS_Code__c> mapOfDescriptionWiseSICCOde = new Map<String,VRNA__SIC_NAICS_Code__c>();
for(VRNA__SIC_NAICS_Code__c sCOdes : [SELECT Name, VRNA__Unique_ID__c,VRNA__Description__c,WC__c,GL__c,GA__c,BOP__c
FROM VRNA__SIC_NAICS_Code__c
WHERE VRNA__Description__c =: sicDesc
LIMIT 1]){
mapOfDescriptionWiseSICCOde.put(sCOdes.VRNA__Description__c,sCOdes);
}
for(Lead oLead : trigger.new){
if(String.isNotBlank(oLead.Description) && mapOfDescriptionWiseSICCOde.containsKey(oLead.Description)){
oLead.WC__c = mapOfDescriptionWiseSICCOde.get(oLead.Description).WC__c;
oLead.BOP__c = mapOfDescriptionWiseSICCOde.get(oLead.Description).BOP__c;
oLead.GA__c = mapOfDescriptionWiseSICCOde.get(oLead.Description).GA__c;
oLead.GL__c = mapOfDescriptionWiseSICCOde.get(oLead.Description).GL__c;
}
}
}