You need to sign in to do that
Don't have an account?
Brianne Wilson
Attach Child Record Based on Field Value (Find Record ID by Value and Attach)
Without getting too wordy:
I have a Zipcode object where the record name is a 5 digit zipcode. (Object Name = Zipcode__c)
I have a lookup field to the Zipcode object on the Account object (Field Name = Zipcode__c)
Goal If BillingPostalCode is not null, on insert/update I want to query the BillingPostalCode of the Account, search for the Zipcode record whose Name matches the Account BillingPostalCode, and attach. Note to query only on update if BillingPostalCode has been updated.
Ex: Account 123 is located in Zipcode 12345. Upon save, the Zipcode record called 12345 is located and attached to the Account in the Zipcode__c lookup field.
I know in theory how the Apex should look (create a list of Zipcode records where Name equals Account.BillingPostalCode), but having difficulty putting it into code. Any takers?
I have a Zipcode object where the record name is a 5 digit zipcode. (Object Name = Zipcode__c)
I have a lookup field to the Zipcode object on the Account object (Field Name = Zipcode__c)
Goal If BillingPostalCode is not null, on insert/update I want to query the BillingPostalCode of the Account, search for the Zipcode record whose Name matches the Account BillingPostalCode, and attach. Note to query only on update if BillingPostalCode has been updated.
Ex: Account 123 is located in Zipcode 12345. Upon save, the Zipcode record called 12345 is located and attached to the Account in the Zipcode__c lookup field.
I know in theory how the Apex should look (create a list of Zipcode records where Name equals Account.BillingPostalCode), but having difficulty putting it into code. Any takers?
All Answers
If you have the Process Builder Beta on your org (you can request it via a support ticket), then you could do this with flow.
Otherwise, you could write a trigger on Account similar to the following:
Note, you could simplify this potentially, by utilizing external ids for the zipcode instead.