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

Lead trigger doesn't recognize custom setting ("Variable does not exist")
Recently I've added trigger on contact populating Area_Code__c field based on the information added to contact.MailingCountry through CountryRegion__c custom setting. It works well:
but when I'm trying to replicate the code on lead:
it does gives me an error: "Error: Compile Error: Variable does not exist: CountryRegion__c at line 5 column 27"
CountThat CountryRegion__c custom setting is the same I've used for contacts, so not sure why the system acan't see it this time? Do I need a new separate custom setting for leads?
Thank you in advance!
trigger PopulateContactAreaCode on Contact (before insert, before update) { for(Contact contact : Trigger.new) { string AreaCode = .getInstance(contact.MailingCountry).Area_Code__c; contact.Area_Code__c = AreaCode; } }
but when I'm trying to replicate the code on lead:
trigger PopulateLeadAreaCode on Lead (before insert, before update) { for (Lead newLead : Trigger.new) { string AreaCode = CountryRegion__c.getInstance(Lead.Country). Area_Code__c; lead.Area_Code__c = AreaCode; } }
it does gives me an error: "Error: Compile Error: Variable does not exist: CountryRegion__c at line 5 column 27"
CountThat CountryRegion__c custom setting is the same I've used for contacts, so not sure why the system acan't see it this time? Do I need a new separate custom setting for leads?
Thank you in advance!
I dont see the CountryRegion__c used anywhere in your contact trigger. In any case, this is your issue. Either the custom setting does not exist or it is named somehting else perhaps? The error is telling you that Salesforce does not know what CountryRegion__c is.
Regards
Stephen
and country region:
So 'string AreaCode = CountryRegion__c.getInstance(Lead.Country). Area_Code__c;' should be 'string AreaCode = CountryRegion__c.getInstance(Lead.Country).Area_Code__c;'