Hi,
I have a trigger to convert object"Lead" to object "Account" when the status is "Won";
However when I update the account record, it will not update the original lead data which will result in the lead data useless and redundant.
I knew one option is to create another trigger to update the lead record to keep synchronize, but just curious is there a better way to do this? or do we need to keep the original leads data at all?
Hi Caylali,
I guess the answer depends on whether you need the old lead data or not. We've done something similar and did write another trigger to manipulate the original object. If you are moving over all the data from the lead to your account when it is done, it is up to you whether you want to just delete the old lead.
If you want to condense your code, you could use the object script trigger type to run the "Create New Record" trigger you are using now, then write the code to update or delete the original lead after the new record is created within that trigger.
If you have more specific questions or I misunderstood what you are attempting, I'd be glad to help.
Thanks,
Jason
Hi Jason,
Thanks for you reply. You got what I mean. I don't want to delete old data, nor set up another trigger. How to write code on the existing trigger to update the original data? As far as I can see, these two records are completely not related after the conversion is complete? I wish there is a check box for me say "synchronize these two data set" :P
Thanks,
Cayla
Hi Cayla,
If you set up a relationship between the Account and the Lead, you should be able to get them to be related. Assuming you are using a conversion map, you would need to set the Lead field to the value of "Source Object" from the drop down. That would ensure they are related after the conversion is complete. As far as updating data on the lead is concerned, I don't know of a way to do this from the conversion itself without moving all of your code to an object script trigger and writing it that way.
I hope this helps.
Jason
Thanks Jason.
It looks like I can only write the script to synchronize these two object.
If anyone have existing codes to share, please let me know. Thanks.
Cayla, Can you post the code you are using today with the object integration names you are working with? That would help me give you some sample code that might work for you.
I had a trigger to create a new record if the the same name is not already existed. I tried below code, but it always returns false no matter the record is exist or not.
var m_Name = '{!name#text}';
var isExist = rbv_api.selectQuery("SELECT firstName FROM Merchant where name=?", 1, m_Name);
if (!isExist) {
return true;
}
else
return false;
Cayla,
When you use the selectQuery api, the result set, even if it is a single record, is stored in an array. You'll need to check if there are actual values in the array instead because even if no record exists, there is still data in the array.
If all you care about is that a record exists with the same name, something like this should work.
var m_Name = '{!name#text}';
var isExist = rbv_api.selectQuery("SELECT firstName FROM Merchant where name=?", 1, m_Name);
if (isExist.length > 0) {
return true;
}
else
return false;