Find Process Builder Name by Id

1 Mar

Deployment errors can be hard to track down when they give vague descriptions like when a Process Builder encounters an error. You end up with something like this.

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30121000000UF54. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []

To figure out what ‘30121000000UF54’ is, the Id can be opened in the Flow designer. Enter the url for the flow designer with the Process Builder id, and the name of the process builder will appear at the top of the page.

// format
https://{node}.salesforce.com/designer/designer.apexp#Id={ProcessBuilderId}

// example
https://na1.salesforce.com/designer/designer.apexp#Id=30121000000UF54

Re-format a Phone Number using Apex

29 Dec

Below is a static method that will reformat a phone number. The method removes characters, and it will check for strings of numbers that are 10 or 11 digits long. The logic would need to be changed to process international numbers.

private static String FormatPhone(String Phone) {
  string nondigits = '[^0-9]';
  string PhoneDigits;
  
  // remove all non numeric
  PhoneDigits = Phone.replaceAll(nondigits,'');
  
  // 10 digit: reformat with dashes
  if (PhoneDigits.length() == 10) 
    return PhoneDigits.substring(0,3) + '-' +
           PhoneDigits.substring(3,6) + '-' +
           PhoneDigits.substring(6,10);
  // 11 digit: if starts with 1, format as 10 digit 
  if (PhoneDigits.length() == 11) {
    if (PhoneDigits.substring(0,1) == '1') {
      return  PhoneDigits.substring(1,4) + '-' +
              PhoneDigits.substring(4,7) + '-' +
              PhoneDigits.substring(7,11);
    }
  }

  // if it isn't a 10 or 11 digit number, return the original because
  // it may contain an extension or special information
  return( Phone );
}