1

I have the following code which uses string concatenation to check the err.getStatusCode()

if (err.getStatusCode()+'' != 'ENTITY_IS_DELETED').

My question is, if there's a cleaner/better way to do this?

err.getStatusCode() returns a type of StatusCode which I wasn't able to find the docs for it in order to see all the possible values, so I appreciate it if anyone can put a link to the docs for that as well. Thanks! 🍻

List<Database.DeleteResult> drList = Database.delete(sObjects, false);
for (Database.DeleteResult dr : drList) {
  if (!dr.isSuccess()) {
      for (Database.Error err : dr.getErrors()) {
        if (err.getStatusCode()+'' != 'ENTITY_IS_DELETED') {
            this.errors.add('DML error during deletion process for Record ID: '+ sObjects.get(drList.indexOf(dr)) +
            ' Record type: '+ sObjects.get(drList.indexOf(dr)).getSObjectType().getDescribe().getName() +
            ' Message: '+ err.getMessage() +' Fields: '+ err.getFields() +' Status code: '+ err.getStatusCode());
            }
        }
    }
}
3
  • 3
    I can't help with the main question, but under the Usage section on the link you posted is this: "The full list of status codes is available in the WSDL file for your organization (see Downloading Salesforce WSDLs and Client Authentication Certificates in the Salesforce online help.)" – Moonpie Jun 18 at 22:55
  • 1
    @Moonpie This should be an answer, not a comment. – sfdcfox Jun 18 at 22:56
  • 1
    @sfdcfox : I was thinking that it was really only half an answer, as I didn't address the OP's bolded question. So I didn't think it right to put it as an answer since it wasn't complete, but I still wanted to help. – Moonpie Jun 18 at 23:22
1

For the first part of the question, I figured it was much simpler than I was thinking, I just simply had to reference the Enum by its type as follows:

if (err.getStatusCode() != StatusCode.ENTITY_IS_DELETED) so I changed the string comparison to just comparing both types as they both are of type StatusCode.

And regarding the second question As @Moonpie pointed out in his comment,

The full list of status codes is available in the WSDL file for your organization (see Downloading Salesforce WSDLs and Client Authentication Certificates in the Salesforce online help.)

and here's what WSDL is and how to download it for your org.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.