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

Simple Lookup Trigger Help
Hello:
I need help writing a basic trigger (at least I think it is basic, I am still new):
I have two Custom Objects:
Household_Address__C
GPON_Address__C
What I would like to do is:
1. From the field Name on GPON_Address__C, lookup to see if there is a matching record in Household_Address__C where the name is the same.
2. If there is a match, return the value from Customer_Name__c that is in Household_Address__C and put it in the Customer__c field on GPON_Address__C.
Long story short, I just want to do the equivelant of a VLOOKUP using GPON_Address__C.name as the reference and using Household_Address__C.name as the match and return Household_Address__C.customer_name__c.
Is this possible?
Hope this was clear, any help writing the code would be greatly appreciated.
Thanks,
Matt
Matt,
Try something like the following --
String GPONName = GPON_Address.name; // Assumption is that GPON_Address is the name of the variable that we are processing.
Household_Address__C householdAddress = [select Household_address__C.Customer_Name__c from Household_Address__C where Household_address__C.name = :GPONName];
if(householdAddress != null)
GPON_Address.Customer_Name__c = householdAddress.Customer_Name__c;
As you will be doing this in a trigger, you should be careful else the trigger will be recursive one and you may end up hitting the governor limits.
Use Trigger.Old and Trigger New while doing this to make a check whether Customer_Name__c in both the objects are not same. Then copy the value and update the object.
Hope this helps.
Got it working, thanks for the help!