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
Antonio_hotelbedsAntonio_hotelbeds 

Convert Lead into a Custom Object

Hi all,

 

we are using the web to lead functionallity in our org to configure groups.

 

Our clients introduce the information about a group in the web and we get this info as a lead. I want to convert these lead into a custom object Groups.

 

I think the best for me would be to create a new button "convert lead into group" using APEX o AJAX but I dont know where to start from. I was reading in this board but I didnt find anything clear.

 

Could you please explain me how to start?

 

Thanks,

 

Antonio

Navatar_DbSupNavatar_DbSup

Hi,


You can do this through a trigger also. You have to create a custom field of type checkbox and made a condition inside the trigger code that if it is true copy this record from lead to custom object and after this delete this record from Lead if you want.

 

Try the below code as reference:
Trigger CreatERecord on Lead (after insert,after update)
{
If(trigger.new[0].CheckConvert__c == true)
{
CustomObject__c cus=new CustomObject__c(name=Truigger.new[0].name,Other fields that you want to keep populate on custom object record)
Insert cus;
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Antonio_hotelbedsAntonio_hotelbeds

Hi Navatar,

 

Thanks for your reply.

 

I was thinking about creating a custom button because I dont want the lead to be converted into an account or contact. I just want the lead to be converted into the object group.

 

According to your solution, I could create a custom button that will activate the trigger you explained.

 

Which would be the code for the button to activate the checkbox and then trigger the trigger?

 

How would you do it creating a button that would work "Onclick Java Script"?

 

Thanks,

 

Antonio

Antonio_hotelbedsAntonio_hotelbeds

Hi,

 

I created a Javascript code that will execute onclick but I cant manage to copy the multipicklist value from the lead to my object Group:

 

This is the code:

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}

var updateRecords = []; //array for holding records that this code will ultimately update

var Grupo = new sforce.SObject("Group__c");
Grupo.Agent__c="{!Lead.Agent__c}";
Grupo.Name="{!Lead.Group_enquiry_number__c}";
Grupo.Group_Source_Market__c="{!Lead.Group_Source_Market__c}";
Grupo.Type_of_Group__c="{!Lead.Type_of_Group__c}";
Grupo.Country_Groups__c="{!Lead.Country_Groups__c}";
Grupo.Destination_Groups__c="{!Lead.Destination_Groups__c}";
Grupo.Region_Groups__c="{!Lead.Region_Groups__c}";
Grupo.Alternative_Destinations__c="{!Lead.Alternative_Destinations__c}";

Grupo.Number_of_Nights__c="{!Lead.Number_of_Nights__c}";
Grupo.Expected_Budget__c="{!Lead.Expected_Budget__c}";
Grupo.Name_of_Hotel__c="{!Lead.Name_of_otel__c}";
Grupo.Type_of_Accommodation__c="{!Lead.Type_of_Accomodation__c}";
Grupo.Category__c="{!Lead.Category__c}";
Grupo.Board_Type__c="{!Lead.Board_Type__c}";

 

//Query to get the account that group will be related to
var cliente= sforce.connection.query("Select Id from Account where AccountNumber='{!Lead.Atlas_Number__c}' and Atlas_Branch_Number__c={!Lead.Branch__c} limit 1");
records = cliente.getArray("records");
for (var i=0; i<records.length; i++) {
var record = records[i];
Grupo.Account_Name__c=record.Id;
}

 

var result = sforce.connection.create([Grupo]);

window.location.reload();

 

And the multipicklist field is Board Type.

 

Thanks,

 

Antonio