Tag Archives: Process Builder

Check Case Owner is a User or Queue

Check Case Owner in Apex Class.

//Check object Id in Apex 
if(string.valueOf(c.OwnerId).startsWith('005')){
    //Owner is User       
}

if(string.valueOf(c.OwnerId).startsWith('00G')){
    //Owner is Queue
}

Check Case Owner in Apex Trigger.

//In Apex Trigger
for (Case objCase : Trigger.new) { 
    If (objCase.OwnerID.getsobjecttype() == User.sobjecttype) {
        /*Code if Owner is User*/
    }
    else{
        /*Code if Owner is Queue*/ 
    }
}

Check Case Owner by SOQL query.

//By Query Owner.Type Field
List<Case> caseList = [SELECT Id, CaseNumber, OwnerId, Owner.Name, Owner.Type FROM Case];

for (Case objCase : caseList){
    If (objCase.Owner.Type == User.sobjecttype) {
        /*Code if Owner is User*/
    }
    else{
        /*Code if Owner is Queue*/ 
    }
}

Check Case Owner in Process Builder.

//Check in Process Builder
BEGINS([Case].OwnerId, "005") //Check Owner is User
BEGINS([Case].OwnerId, "00G") //Check Owner is Queue

Difference between Process Builder and Workflow in Salesforce

Process builder allows you to do the below actions:

  • Create a new record.
  • Update any related record.
  • Quick action creates or updates record or log call.
  • Launch a flow.
  • Send an email
  • Post to Chatter.
  • Submit for approval
  • Call apex methods
  • But the process builder doesn’t support outbound messages.

Workflows can only handle four types of actions:

  • Create Task.
  • Update Field.
  • Email Alert.
  • Outbound Message.

Invocable Method in Salesforce

We use @InvocableMethod annotation, whenever we want to invoke an apex method from the Process Builder then that method must be declared as @InvocableMethod, otherwise it can’t be accessed in Process Builder.

Invocable Annotation Method Example:

public class AccountAction {
    @InvocableMethod(label='Update Account' description='Update the list of accounts to the specified account IDs.')
    public static void updateAccounts(List<Id> ids) {
       
    }
}

Use Cases of Invocable Method:

  • The Invocable method must be static and public or global, and its class must be an outer class.
  • Only one method in a class can have the InvocableMethod annotation.
  • Triggers can’t reference Invocable methods.
  • Invocable method will not accept more than one argument as a method parameter
    Other annotations can’t be used with the InvocableMethod annotation.

Inputs and Outputs of Invocable Method:
There can be at most one input parameter and its data type must be one of the following:

  • A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
  • A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
  • A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
  • If the return type is not Null, the data type returned by the method must be one of the following:
    • A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
    • A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
    • A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.

Invocable Methods in Managed Packages:

  • We can use InvocableMethod in packages, but once we add an Invocable method, we can’t remove it from later versions of the package.
  • Public Invocable methods can be referred to by flows and processes within the managed package.
  • Global Invocable methods can be referred to anywhere in the subscriber org. Only global Invocable methods appear in the Cloud Flow Designer and Process Builder in the subscriber org.