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

Trouble with Lead Conversion

I wrote and s-control to convert a number of leads from a leads view.  It works fine as long as I want duplicate accounts created.
I check to see if the account exists and if so get the ID.  I can displaye the ID using an alert so I know I got it and it is correct.  I put the Id into convert.accountId yet when I call leadConvert the accountId is null. 
I have added the code in case I am making a stupid mistake.   I changed the Status to something that is invalid so I get an error that shows me what is being passed.  The leadId is passed correctly but not the accountId. Thanks for any help.
var convert = new sforce.LeadConvert();
convert.leadId = records[i].Id;
//Now check if account already exists and if it does also check if contact exists
//alert("SELECT ID from Account WHERE Account.Name='" + records[i].Company + "'");
var account = sforce.connection.query("SELECT ID from Account WHERE Account.Name='" + records[i].Company + "'");
if  (account.size > 0)
            var accrec = account.getArray('records');
            convert.accountId = accrec[0].Id;
alert("Acct ID: "+ convert.accountId + " and Lead Id "+ convert.leadId);
            var contact = sforce.connection.query("SELECT ID from Contact WHERE Contact.Name='" + records[i].Name + "'");
           if  (contact.size > 0)
                var contrec=contact.getArray('records');
convert.convertedStatus = "AClosed - Converted";
var saveResult = sforce.connection.convertLead([convert]);
Use firebug for debug.

I think you are missing some required app field value. Just check passing query through firebug.
I got it to work by changing the way I accessed the accountId I received back from the query. I needed to use GetArray("records")