Thursday, 6 December 2012

Initiate approval process via VF button

Initiate approval process via VF button

In VF
<apex:commandButton value="Submit for Approval" action="{!sumbitForApproval}">

In class


public PageReference sumbitForApproval(){
      PageReference submitPageRef;
      if(sportDeal.Id!=null)
      {
      sportDeal.Submit_for_Approval__c=true;
      sportDeal.Is_Approved__c = false;
      sportDeal.Is_Rejected__c=false;
      upsert sportDeal;
      }
     
     
     // submitPageRef = save();
               try{
                   Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                   req.setComments('Submitting request for approval');
                   req.setObjectId(sportDeal.Id);
                   Approval.ProcessResult result = Approval.process(req);
              }catch (Exception ex){
                  System.debug('Exception caught');
              }
         //return submitPageRef;
         return null;
  }

No comments:

Post a Comment

Why to use Database.Stateful()?

Database Stateful is interface. It is used in batch classes to maintain the state of the class across transactions i.e. if you want to use ...