function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rom_Rom_ 

Trigger to update lookup field with id from text field on same object (Account)

Text_ID__c - text field with id of an Opportunity
A_Opportunity__c - lookup field to Opportunity

Both fields are in standard Account object. How can I populate the lookup field with the id in the text field? Will not work with workflow or process builder, guess I need Apex trigger (with which I have little experience). Can anyone provide code for this to at least put me on the right track? Would greatly appreciate it :)
Abhishek BansalAbhishek Bansal
Hi,

Please use the below trigger code :
trigger updateOppField on Account(before insert, before update){
	for(Account acc : trigger.new){
		if(acc.Text_ID__c != null){
			acc.A_Opportunity__c  = acc.Text_ID__c;
		}
	}
}
Let me know if you need any further help on this.

Thanks,
Abhishek
Rom_Rom_
Hi Abhishek,

    I really appreciate the help. Unfortunately it failed on deployment to production.
Error Message: Methods defined as TestMethod do not support Web service callouts 
Stack Trace: null

Any idea how to resolve this?
Thanks again.
Abhishek BansalAbhishek Bansal
I think it is a different question than the one that you have asked on this forum so i would suggest you to close this one right here and put your new question on a different forum. That will avoid the confusion and will help others in finding right solition at right place. Please do not mix up different questions on a single forum. Create a new question with your current problem and send me the link of new question here. I will definitely reach you out there as soon as possible and will provide you the best possible solution from my side
Abhishek BansalAbhishek Bansal
Thanks a lot for following the baiscs.
Please close this question by marking it as Solved if you do not have any further queries on it.