I am wondering is it possible to rollback when external user creation fails after password do not meet org requirements?
A detailed explanation: I am currently using createExternalUser method in order to create a community user. I create an account from user inputs then a user instance. Finally I use following code to create my community user.
Site.createExternalUser(userInstance, accountId, password);
User creation returns null (it should return userId). I use standard Exception and Site.ExternalUserCreateException and both of then do not catch any exception and method returns null. When VF page refreshed I face with password error in apex:pagemessage tag. At this point I have an account created in Salesforce, which I want to rollback. My version is 40, document suggests that it is possible if I can catch the error:
Calls to this method in API version 30.0 and later won’t commit the transaction automatically. Calls to this method prior to API version 30.0 commit the transaction, making it impossible to roll back to a save point before the call.
Edit: As Tushar mentioned, I am currently triggering a database rollback if userId is null, but does anyone know why method doesn't throw any exception, or why I face with an error on my VF page if there is no exception thrown?