+ Start a Discussion
Trupti BaroleTrupti Barole 

Do i need to create a REST API to convert a Lead?

Hi experts,
I'm stuck in developing a hybrid salesforce mobile application.
The scenario is i'm using forcetk.mobilesdk.js for accessing LEAD object in salesforce and i want to display a button CONVERT on clicking which a convert query should get fired and that particular Lead should be converted into Opportunity. There are various APIs in forcetk.mobilesdk.js file to create, delete, retrieve and so on. But i did not find any to convert a Lead to opportunity/account/contact.

Do i need to create a new API so that i can convert LEAD? or there is any alternate way to achieve the same?? 
If i must create a API, how can i create??

For reference, https://github.com/forcedotcom/SalesforceMobileSDK-Android  run an AccountEditor app and understand functionality and please help ASAP.

code sample for creating a record is in code sample.
     * Creates a new record of the given type.
     * @param objtype object type; e.g. "Account"
     * @param fields an object containing initial field names and values for
     *               the record, e.g. {:Name "salesforce.com", :TickerSymbol
     *               "CRM"}
     * @param callback function to which response will be passed
     * @param [error=null] function to which jqXHR will be passed in case of error
    forcetk.Client.prototype.convert = function(objtype, fields, callback, error) {
        return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/'
        , callback, error, "POST", JSON.stringify(fields));

I want to write a code for Convert Lead.
Yes you have to create custom REST apex class for this. Create your own apex REST webservice class which will convert the lead record into Account, Contact and Opportunity. Here is the sample code for writing the logic for converting lead process in apex class- http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_convertLead.htm

Check this link for how to create REST apex class in salesforce - http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_code_sample_basic.htm

Now you have created a custom REST API class which will convert your lead, now call your REST apex class in your code to convert lead like the other REST API call.