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
Jordan@BracketLabsJordan@BracketLabs 

Determine if Approval Process exists for recordtype

I need to determine if an approval process exists for my object in an org, dynamically, so I can determine if I should display a 'Submit for Approval' button.

 

I can't find anyway to directly query for the existance of an Approval Process, (the standard recordtype: Approval, I believe, relates specific approvals that are already started for a particular object, I can't test these, as I need to know, ideally before any of them exist)

 

I thought about trying to start an approval for the current record and trapping the error message, but, if it succeeded, than the record would be submitted for approval (by the test):

 

try{
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setObjectId(this.object.id);
Approval.ProcessResult result = Approval.process(req);	
}
catch(exception e){
 if(e.contains == "Some ERROR")
   //set my flag
}

 

Thoughts? Am I just missing something?

 

 

 

AlagarAlagar

To determine the Approval process for an object, pls check whether Process Instance Object is present for the particular object. If it has then ur object has an Approval process.

 

for ur reference: Process Instance Object

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_processinstance.htm

Jordan@BracketLabsJordan@BracketLabs

I tried this (just by using the schema browser in the Eclipse IDE and I didn't see any results, after I created a process in the point & click interface).

 

On the document page it says there is a field: "TargetObjectId" is the ID of any object of the type in question?

 

MyObject__c newObjectWithApprovalProcess = new MyObject__c();
insert newObjectWithApprovalProcess;

List<ProcessInstance> pi = [SELECT TargetObjectId FROM ProcessInstance WHERE TargetObjectId = :newObjectWithApprovalProcess.Id];

if(pi.size() > 0){
system.debug('ApprovalProcess exists for type MyObject__c');
}

 

Jordan@BracketLabsJordan@BracketLabs

On further investigation, your solution isn't what I was looking for: querying the ProcessInstance records only applies to records that have already been submitted for approval.

 

I am looking to determine if an applicable approval process is avaliable to the record in it's current state before one has been submitted. 

PjnickPjnick

Did you ever find a solution to this problem?  I'm trying to do the same thing.

 

Thanks!

JordanP323JordanP323

Hi Jordan, 

 

I realize that it has been awhile, but I was able to find the solution to your issue. You can access the approval process class, which holds all the metadata for approvals. From there, you should be able to pull out if an approval process exists for your org. This is valid for API version 28.0 and greater. 

 

You can find more info on this object here: http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_approvalprocess.htm

 

Good luck!

Saravanan @CreationSaravanan @Creation
Hi Jordan,

Did you find any solution to resolve this. If yes please let me know.

Thanks in advance!!