You need to sign in to do that
Don't have an account?
Michael Allen
Attaching child records using ID held on parent
Hi all,
I'm very new to Apex, but am convinced this scenario is possible. Problem is I can't find any examples anywhere, which surprises me.
I have a text field on Account called 'Originating_Lead__c' containing the 18 char ID of a Lead.
On the Lead is a lookup to Account.
I want to insert the ID of the Account record into the Account lookup field on the Lead record that corresponds to the ID held in the Originating_Lead__c field on Account.
I'm know I can't do this declaratively as it's "going down the tree", but I'm surprised this issue hasn't crept up before on here - have trawled right through and haven't found anything. Does anybody know of any examples of similar triggers for similar problems?
Have browsed and used this community extensively but never posted a question - never needed to!
Thanks in advance.
Michael
I'm very new to Apex, but am convinced this scenario is possible. Problem is I can't find any examples anywhere, which surprises me.
I have a text field on Account called 'Originating_Lead__c' containing the 18 char ID of a Lead.
On the Lead is a lookup to Account.
I want to insert the ID of the Account record into the Account lookup field on the Lead record that corresponds to the ID held in the Originating_Lead__c field on Account.
I'm know I can't do this declaratively as it's "going down the tree", but I'm surprised this issue hasn't crept up before on here - have trawled right through and haven't found anything. Does anybody know of any examples of similar triggers for similar problems?
Have browsed and used this community extensively but never posted a question - never needed to!
Thanks in advance.
Michael
Thanks so much for this. It works a treat.
This has opened up a huge door for me, as we have similar scenarios elsewhere that need addressing in a similar manner.
I may pop back in time if I have issues with them.
Thanks again
Michael
The only difference for me is where the lookup field is. If I compared it to your case, it would be that I had a lookup field on the Account to the Lead, and I'd want to find the Lead that matches that 18 character code and attach it TO the account (rather than the other way around).
If anyone can please help my similar case I'd much appreciate it!
Could anybody lend a hand with a test class for this? I've made a start, but I'm working off the basic sample versions from the SF help articles. I'm not sure how to make it do the actual test, as the trigger updates a field on Lead from an ID held on Account. So how do I write a test to look at Lead? Does it need to insert 2x temporary records - a Lead and an Account?
As you can see from earlier, the field 'Originating_Lead__c' on Acct contains an 18 digit ID (populated on creation via URL). The trigger then finds this lead and updates the Account__c lookup with the ID of the Account from which the trigger fired.
Thanks
Michael
Brianne, I read your thread and saw you had success getting a solution. Congrats.