• JordanP323
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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?