• justin brown 7
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi all,
I have created a controller extension class as a work around to the approval processs for my visualforce page. This extension is suppsoed to update the status picklist field when the submit button is clicked and update the record if the record had been perviously saved but not submitted. However when I click the button it simply refreshes the page with no field update and no save. Any feedback on what I'm doing wrong?

VF Page Button:

<button class="btn waves-effect waves-light" type="submit" name="action">Submit
       <apex:commandButton action="{!setStatus1}" reRender="status"/>
               <i class="material-icons right">send</i>                                                                                
   </button>     
Controller Class:

public with sharing class ApprovalProcessExtension {
    
    private ApexPages.StandardController standardController;
    public CIOA_Submissions__c subs {get; set;}
    public ApprovalProcessExtension(ApexPages.standardController stdController){
        subs=(CIOA_Submissions__c) stdController.getRecord();
    }
    
    public pageReference setStatus1() {
        subs.Submission_Status__c = 'Pending';
        update subs;
        system.debug('setStaus1'); 
        return null;
    }
    public pageReference setStatus2() {
        subs.Submission_Status__c = 'Long Form';
        update subs;
        return null;
    }
     public pageReference save(){
      pagereference pref = new pagereference('/apex/CIOA_Nominations');
        pref.setRedirect(true);                
        return pref;
     }  
}
Hi All,

I am attemtping to create a controller extension class that allows me to give two buttons on my VF page added functionality. I have a submit botton which should update a status picklist field thats on the object but not on the VF page, trigger an email notification to the record owner, and lock the record. I also have a similar button that should chage the status picklist value again and save the record. Any ideas on how i can get all of this functionality in two buttons using controller extensions?

Thanks

Hi All, Im attemtping to write a controller extention to the standard controller "CIOA_Submissions__c" I have a created a VF page which serves as my submission form and it is being controlled by the standard controller. I need my extension to render the approval process via a 'submit' commandbutton, and also have the record approved from the visual force page via the 'approve' commandbutton. I get an invalid type for "Approval.ProcessWorkitemRequest". Any suggestions on code corrections?

public class ApprovalExtender{
CIOA_Submissions__c extension;

public ApprovalExtender(ApexPages.standardController stdController){
    this.extension=(CIOA_Submissions__c) stdController.getRecord();
}

public override void int(){
}

public PageReference approve(){
   Id id=ApexPages.currentPage().getParameters().get('id');
    
    Integer cnt=[SELECT COUNT() FROM Processinstance WHERE TargetObjectid = :id AND Status='Pending'];
    System.debug ('count=' + cnt);
    if(cnt==0){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Not pending record'));
        return null;
    }
    return null;
}
    Id processId=[SELECT Id FROM ProcessInstance WHERE TargetObjectId = :id AND Status = 'Pending' Limit 1].Id;
    Id workitemId=[SELECT Id FROM ProcessInstanceWorkItem WHERE ProcessInstanceId = :processId Limit 1].Id;
    
    Approval.ProcessWorkitemRequest = new Approval.ProcessWorkitemRequest();
    request.setAction('Approve');
    request.setNextApproverIds(new Id[]{UserInfo.getUserId()});
    request.setWorkitemId(workitemId);
    Approval.ProcessResult result=Approval.process(request);
    
    if(result.isSuccess()){
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Submission Approved'));
        }
        else{
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Submission Pending'));
        }
        return null;
    }
     
     public PageReference submit(){
         Id id=ApexPages.currentPages().getParameters().get('id');
         
        Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval');
        req1.setNextApproverIds(new Id[]{Userinfo.getUserId()});
        req1.setObjectId(id);
        Approval.ProcessResult result = Approval.process(req1);
         
          if(result.isSuccess()){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Submission Submitted Successfully'));
        }
        else{
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity,ERROR,'Submission Not Submitted Please Try Again'));
        }
        return null;
        }
     }
Hello All,

I have a VF page that contains fields relevant to a submission form. This VF page is currently being controlled by a standard controller and the object has an associated approval process. I was wondering what a controller extension would look like in order to have the user input their information submit the form (via) VF page and submit it for approval, Have the appropriate approver view the record on the VF page and approve it by simply checking a box on the VF page. 
 
Hi All,

I am attemtping to create a controller extension class that allows me to give two buttons on my VF page added functionality. I have a submit botton which should update a status picklist field thats on the object but not on the VF page, trigger an email notification to the record owner, and lock the record. I also have a similar button that should chage the status picklist value again and save the record. Any ideas on how i can get all of this functionality in two buttons using controller extensions?

Thanks