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

Parse 'exception code' in Apex
Is there a way to parse just the exception code while making calls like insert user, System.setPassword etc.
The error message show:
Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []
Failure : INVALID_NEW_PASSWORD: Your password must be at least 5 characters long.
But now sure how to just get PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT , INVALID_NEW_PASSWORD
List of exception codes: https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_concepts_core_data_objects.htm#i1421192
The error message show:
Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []
Failure : INVALID_NEW_PASSWORD: Your password must be at least 5 characters long.
But now sure how to just get PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT , INVALID_NEW_PASSWORD
List of exception codes: https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_concepts_core_data_objects.htm#i1421192
System.debug(e.getMessage());
System.debug(e.getCause());
System.debug(e.getLineNumber());
System.debug(e.getMessage());
System.debug(e.getStackTraceString());
System.debug(e.getTypeName());
if(e.getTypeName() == 'System.DmlException'){
System.debug(e.getDmlFieldNames(0));
System.debug(e.getDmlFields(0));
System.debug(e.getDmlId(0));
System.debug(e.getDmlIndex(0));
System.debug(e.getDmlMessage(0));
System.debug(e.getDmlStatusCode(0));
System.debug(e.getDmlType(0));
System.debug(e.getNumDml());
}