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

createportaluser and custom contact details
I need to create a ready-to-login community user with prespecified password and corresponding contact and account. Contact and account have custom fields that need to be populated as part of this.
None of the available CreatePortalUser methods offer the ability to specify a contact, but I found some code (see link below) to manually create the user and link to a contact.
https://developer.salesforce.com/page/ExampleApexCustomerPortalUser
The problem I have with this code is it's not possible to set the password as part of the user insert, and adding a subsequent system.setPassword() call in the same transaction doesn't work. Weirdly, if I execute setPassword again immediately after in developer console then it works.
It seems that if the password isn't set during user insert then SFDC sends out the first time login link and won't accept a setPassword during the same transaction?
If so I can't get around it by putting the setPassword in a @future call because this code already has an @future call and you can't nest them.
Any insights or suggestions to get around this?
None of the available CreatePortalUser methods offer the ability to specify a contact, but I found some code (see link below) to manually create the user and link to a contact.
https://developer.salesforce.com/page/ExampleApexCustomerPortalUser
The problem I have with this code is it's not possible to set the password as part of the user insert, and adding a subsequent system.setPassword() call in the same transaction doesn't work. Weirdly, if I execute setPassword again immediately after in developer console then it works.
It seems that if the password isn't set during user insert then SFDC sends out the first time login link and won't accept a setPassword during the same transaction?
If so I can't get around it by putting the setPassword in a @future call because this code already has an @future call and you can't nest them.
Any insights or suggestions to get around this?
Insert Account
Call CreatePortalUser specifying the Account and password
In an @future call, find the Contact that was created and update its details