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

How do I get a field to populate with text based on the value of another field?
I have a custom object named County that houses all U.S. data for zipcodes and counties.
I have a County custom field on my contacts.
I need help creating a simple trigger that will update the County field on my contact. I want to match the zipcode on the contact with the zipcode on the county object and return the value of the county.
Screen shots are below:


I have a County custom field on my contacts.
I need help creating a simple trigger that will update the County field on my contact. I want to match the zipcode on the contact with the zipcode on the county object and return the value of the county.
Screen shots are below:
Hi Dea
Try this
countyTrigger on Contact (after Insert, after Update)
{
Contact con = trigger.new();
County__c listCounty = [select county__c from county_Object__c where ZipCode__c = con.ZipCode__c];
if(listCounty!=null)
{
con.County__c = listCounty.county__c;
}
}
*This is just an example. Please replace appropriate APIs
If this resolves your issue, please mark this as an answer
Sorry Dean,
You cannot update fields on after trigger. Ooops! My Bad. Here's the updated code
trigger countyTrigger on Contact (before Insert, before Update)
{
for (Contact con : trigger.New)
{
County__c listCounty = [select county__c from county__c where ZipCode__c =: con.ZipCode__c];
if(listCounty!=null)
{
system.debug('------'+listCounty);
con.County__c = listCounty.county__c;
}
}
}
Pleae mark this as the answer if it resolves your issue
Regards,
Madhura