function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saravanan @CreationSaravanan @Creation 

Checking object has approval process

Hi All,

I have object called MyCustom__c object. In my controller I want to check whether this object has any approval proceess?
If its possible please help me to achieve this.


Thanks,
Saravanan.

Best Answer chosen by Saravanan @Creation
shiv@SFDCshiv@SFDC
List<ProcessDefinition> ProcessDefinitionList = [SELECT TableEnumOrId FROM ProcessDefinition] ;

//above code give you list of all objects for which approval process is defined..

for(ProcessDefinition rec : ProcessDefinitionList)
{
    processDefSet.add(rec.TableEnumOrId) ;
}

if(processDefSet.contains('my custom object is there')) {
    //do whaterver you want to do.
}



--------------
List<ProcessDefinition> ProcessDefinitionList = [SELECT TableEnumOrId FROM ProcessDefinition WHERE TableEnumOrId ='MyCustomObj__c'] ;

if(ProcessDefinitionList.size > 0) {
  // It mean approval process is there related to your object.
}


All Answers

shiv@SFDCshiv@SFDC
You can make a query on ProcessInstance objct .
If your MyCustom__c object Id is availabel in TargetObjectId it means there is a approvale process related to your custom object.

Please see detail document here.

Process Instance (https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_processinstance.htm)

Saravanan @CreationSaravanan @Creation
Hi Shiva,

I want to check only is there any approval process specified for the object not that record.

Thanks,
shiv@SFDCshiv@SFDC
List<ProcessDefinition> ProcessDefinitionList = [SELECT TableEnumOrId FROM ProcessDefinition] ;

//above code give you list of all objects for which approval process is defined..

for(ProcessDefinition rec : ProcessDefinitionList)
{
    processDefSet.add(rec.TableEnumOrId) ;
}

if(processDefSet.contains('my custom object is there')) {
    //do whaterver you want to do.
}



--------------
List<ProcessDefinition> ProcessDefinitionList = [SELECT TableEnumOrId FROM ProcessDefinition WHERE TableEnumOrId ='MyCustomObj__c'] ;

if(ProcessDefinitionList.size > 0) {
  // It mean approval process is there related to your object.
}


This was selected as the best answer
shiv@SFDCshiv@SFDC
If above answer fix your issue, please marks answer as a solution.