You need to sign in to do that
Don't have an account?
Replace lookup field value with text field value (need id?)
Hi,
We are using an integrated web-to-lead application, and the lookup field cannot be sent. Therefore, the value is sent as text to a text field in Lead object in Salesforce. I then need to convert/copy the value in the text field to the lookup field. How do I get the ID of the value in the text field sent by the web-to-lead form? If I get the ID, I can maybe use this on the lookup field instead?
This is my Apex code:
public class LeadProperty {
public static void convertLeadProperty(Lead lead) { // triggers before insert
lead.Property__c = lead.Property_text__c; // Need to get ID of property text to put it in property lookup field. Maybe via SQL?
}
}
And trigger:
trigger LeadConvertPropertyTrigger on Lead (before insert) {
Lead lead = Trigger.new;
LeadProperty.convertLeadProperty(lead);
}
This code is probably wrong? My first try.
You do not to query anything since lookup field can be assigned with the text values directly. Just need some updates on the trigger as well as helper class. Please find the updated one below:
Trigger: Helper Class:
Please try with the above updated code and let us know if you face any issues with this.
Thanks,
Abhishek Bansal.
Hi Abhishek,
Thanks for your reply! I tried your solution. The implementation looks like this now:
Class:Trigger:
But when the trigger is active no leads come in. If I disable the trigger the leads come in again. So there must be something wrong with here?
Hi Eirik,
Did you saw any error when the trigger is active. Can you confirm the Property_text__c field consist a single id of the Property__c object record. Also you need to make sure that the Property record should exist in your org with the id stored in the Property_text__c field.
It would be good if you can contact me on gmail or skype so that we can debug the issue and find out the right solution.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Thanks,
Abhishek Bansal