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
toddmcgrathtoddmcgrath 

convertLead and existing Person Account

Hello,

 

Does convertLead work with an existing Person Account?

 

 

void testConvertLeadFromStudentAccount() { // use test lead created via Browser def lead = salesForceService.getAllObjects(Lead.class, "Email = 'testonly@na.com'")[0] assertNotNull("should have returned lead", lead) def first = "StudentAPIFirst" def last = "StudentAPILast" println "creating person account" Account acct = new Account() acct.name = '' def studentaccount = getRecordTypes().find { it.name =='Student Account' } println "stud id: ${studentaccount.id}" acct.recordTypeId = studentaccount.id acct.ownerId = salesforce_owner_id acct.gender__pc = '' acct.languages__pc = '' acct.firstName = first acct.lastName = last acct.salutation = '' acct.level__pc = '' acct.personEmail = 'testonly@na.com' SaveResult[] result = salesForceService.createObjects(acct) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have created account", it.success) println "Account ID: ${it.id}" acct.id = it.id } println("lead id: ${lead.id}") LeadConvertResult[] convResult = salesForceService.convertLead(lead.id, '', acct.id, false, false, "opp name", 'Closed - Converted', false, salesforce_owner_id) convResult.each { LeadConvertResult it -> it.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have converted lead", it.success) } }

 

Code is sending the person account.id and '' for the contact.id to the convertLead code.

 

Error returned is:

cannot associate a contact with a consumer account

 

any ideas?  suggestions?

 

 

toddmcgrathtoddmcgrath

And if I try to use both Account and Contact id:

 

void testConvertLeadFromStudentAccount() { def lead = salesForceService.getAllObjects(Lead.class, "Email = 'testonly@na.com'")[0] assertNotNull("should have returned lead", lead) def first = "StudentAPIFirst" def last = "StudentAPILast" println "creating person account" Account acct = new Account() acct.name = '' def studentaccount = getRecordTypes().find { it.name =='Student Account' } acct.recordTypeId = studentaccount.id acct.ownerId = salesforce_owner_id acct.gender__pc = '' acct.languages__pc = '' acct.firstName = first acct.lastName = last acct.salutation = '' acct.level__pc = '' acct.personEmail = 'testonly@na.com' SaveResult[] result = salesForceService.createObjects(acct) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have created account", it.success) println "Account ID: ${it.id}" acct.id = it.id } Contact contact = salesForceService.getAllObjects(Contact.class, "AccountId = '${acct.id}'")[0] assertNotNull("should have returned lead", contact) LeadConvertResult[] convResult = salesForceService.convertLead(lead.id, contact.id, acct.id, false, false, "opp name", 'Closed - Converted', false, salesforce_owner_id) convResult.each { LeadConvertResult it -> it.errors.each { com.sforce.soap.partner.Error er -> println "Lead Convert ERROR: ${er.getMessage()}" } assertTrue("should have converted lead", it.success) } }

 

 I receive:

Lead Convert ERROR: invalid cross reference id

 

The same code works when the the Account is not a Person Account.

 

?

 

 

toddmcgrathtoddmcgrath

Any suggestions?  Still wrestling with this.