You need to sign in to do that
Don't have an account?

create new Person Account via API
Hello,
I'd like to create a new Person Account via API. I have Person Account enabled. Ideally, I want to create a Person Account in one shot, but I don't think it's possible? I need to create an Account and 1 associated Contact and then convert the account to a Person Account type?
void testCreateAndDestroyStudentAccount() { def first = "APIFirst" def last = "APILast" // create new, non-person Account first Account acct = new Account() acct.name = "${last}" def organizationaccount = getRecordTypes().find { it.name =='Educational Organization' } acct.recordTypeId = organizationaccount.id acct.ownerId = salesforce_owner_id acct.gender__pc = '' acct.languages__pc = '' acct.firstName = '' acct.lastName = '' acct.salutation = '' acct.level__pc = '' 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 "creating contact..." Contact contact = new Contact() contact.setFirstName(first) contact.setLastName(last) contact.accountId = acct.id contact.recordTypeId = '' contact.ownerId = salesforce_owner_id result = salesForceService.createObjects(contact) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "Create contact ERROR: ${er.getMessage()}" } assertTrue("should have created contact", it.success) println "CONTACT ID: ${it.id}" contact.id = it.id } def studentaccount = getRecordTypes().find { it.name =='Student Account' } acct.recordTypeId = studentaccount.id result = salesForceService.updateObjects(acct) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "Update Account ERROR: ${er.getMessage()}" } fail("should have converted to Person Account") } }
Code creates an Account and Contact fine, but fails at the update when attempting to convert to a Person Account (at the end) with message:
Cannot specify any additional fields when marrying or separating a Person-Account
Ideas? Thoughts? Suggestions?
I appreciate any insight
Todd
Thanks so much for reply. I have been trying to create in one shot; e.g.
void testCreateAndDestroyStudentAccount2() { println "creating account" Account acct = new Account() // acct.name = "${last}, ${first}" def studentaccount = getRecordTypes().find { it.name =='Student Account' } acct.recordTypeId = studentaccount.id acct.ownerId = salesforce_owner_id //acct.isPersonAccount = true acct.gender__pc = '' acct.languages__pc = '' acct.firstName = "StudentAPIFirst" acct.lastName = "StudentAPILast" acct.salutation = '' acct.level__pc = '' SaveResult[] result = salesForceService.createObjects(acct) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have created person account", it.success) println "Account ID: ${it.id}" acct.id = it.id } DeleteResult[] delresult = salesForceService.delete(acct.id) delresult.each { DeleteResult del -> del.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have deleted student account", del.success) } }
But always error:
happens regardless of whether acct.Name is set or not; example of above does to set Name.
any ideas?
Well, I don't get it, but here's the fix
void testCreateAndDestroyStudentAccount2() { println "creating 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 = "StudentAPIFirst" acct.lastName = "StudentAPILast" acct.salutation = '' acct.level__pc = '' SaveResult[] result = salesForceService.createObjects(acct) result.each { it.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have created person account", it.success) println "Account ID: ${it.id}" acct.id = it.id } DeleteResult[] delresult = salesForceService.delete(acct.id) delresult.each { DeleteResult del -> del.errors.each { com.sforce.soap.partner.Error er -> println "ERROR: ${er.getMessage()}" } assertTrue("should have deleted student account", del.success) } }
If you use custom text input fields on the new account page and then set the Account.FirstName Account.LastName fields in the controller to the values of your custom fields you should be fine. Also if you want to take advantage of Visualforce input fields, just use a contact in the controller (to provide input fields for the first and last names) and map the entered data to the Account.FirstName and Account.LastName fields in the controller when you save (don't save the Contact.)
The problem is that unlike other standard account fields which are prefixed by person (such as PersonMailingCity ) or custom account fields identified as customfield__pc the Account.LastName and Account.FirstName on a person account are not distinguished from the contact equivalents Contact.FirstName and Contact.LastName, which looks like a bug, but as it has been around so long I think it counts as a feature now......
Going back to the original posting and the difficulties surrounding "marrying" an regular Account and its sole Contact into a Person Account in the same transaction that creates both objects.
The (nonobvious) solution here is that, when you change the RecordType of the Account, you need to be operating on an Account object that has nothing but its Id defined.
In other words, this does NOT work:
It fails with "INVALID_FIELD_FOR_INSERT_UPDATE, Cannot specify any additional fields when marrying or separating a Person-Account []"
However, re-fetching the "a" record with only its Id lets the whole thing work:
If you want to create a PersonAccount, it would probably be best not to bother with the contact at all.
The trick is to set a PersonAccount recordtypeId when you save it. I called it "Person Account" below.
Like this (a snippet from a web-to-case solution):
Cheers /Mats
I am only a Certified Salesforce Administrator but I require some guidance on the following.
We are setting up an Enterprise WSDL API
Once syncronised by way of the external data being updated with current record Id's I'd like it so that we can write a trigger to create a Person Account if the Account ID is blank.
Thoughts?