• Beat
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi, I'm trying to perform an approval action through APEX code, in an extended controller.  

First I do a Submit for Approval, overwriting the standard one with a visualforce custom button. Here is the code in my extended controller:

 

public PageReference submitApproval() { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); req1.setObjectId(purchaseRequisitionObj.id); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); return Page.PR_Detail_VF; }

After that event, the object left in "Pending" approval state. Then in my detail visualforce page, for specific cases, I have a "Direct Approval" button. That button should perform the instance approval changing its state to "Approved". Here is where I'm stuck, because I can not find the way to get the WorkitemId of the request. I mean the workitemId of the instance I asynchronously approved before. This is the code:

 

public PageReference directApproval() { // Instantiate the new ProcessWorkitemRequest object and populate it Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest(); req2.setComments('Direct approval by requester'); req2.setAction('Approve'); req2.setNextApproverIds(new Id[] {UserInfo.getUserId()}); req2.setWorkitemId("FROM WHERE I CAN GET THIS ID??"); // Submit the request for approval Approval.ProcessResult result2 = Approval.process(req2); return Page.PR_Detail_VF; }

 

Any cue will be highly appreciated. Many thanks in advance Fernando.-

 

  • July 14, 2009
  • Like
  • 0

Hi,

 

I'm not able to get the inputField values passed into my extended controller. Need that to do some calculations in my apex code and refresh the visualforce page to show the new calculated values to the user.

Here share the code I have up to now:

 

Visualforce code: (please see the line comments on it)

 

<apex:page standardController="Cnno_Purchase_Requisition__c" extensions="PurchaseRequisitionController" id="PR_New_page"> <apex:SectionHeader title="Purchase Requisition" subtitle="New Purchase Resquisition" /> <apex:form > <apex:pageblock title="Purchase Requisition Creation" mode="edit" id="block"> <apex:pageMessages /> <apex:pageBlockButtons location="both"> <apex:commandButton action="{!save}" value="Save"></apex:commandButton> <apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton> <apex:commandButton action="{!doRefresh}" value="Refresh Values" rerender="block"></apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection columns="2" title="Information"> <apex:outputField value="{!PurchaseRequisition.OwnerId}"/> <apex:outputField value="{!PurchaseRequisition.Status__c}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="Item Requested"/> <apex:outputPanel id="item"> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Item_Requested__c}"> <!-- apex:actionSupport event="" rerender="item" status="status"/ --> </apex:inputField> <!-- apex:actionStatus startText="applying value..." id="status"/ --> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Request_Date__c}"/> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Required_Item_Description__c}"/> <apex:outputField value="{!Cnno_Purchase_Requisition__c.Item_Requested__r.Standard_Cost__c}"/> <!-- THIS IS NOT SHOWN!! --> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Ship_To_Location__c}"/> <apex:pageBlockSectionItem > <apex:outputlabel value="Total Amount" /> <apex:outputtext value="{!totalamount}"/> <!-- This throught NULL when refresh performs --> </apex:pageBlockSectionItem> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Max_to_pay__c}" /> </apex:pageBlockSection> <apex:pageBlockSection columns="1" title="Additional Notes"> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Additional_Notes__c}"/> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>

 

APEX Code in extended controller:

 

public class PurchaseRequisitionController { private Cnno_Purchase_Requisition__c purchaseRequisitionObj; private Cnno_Purchase_Items__c item; private String vendor; private Double totalAmount; public PurchaseRequisitionController(ApexPages.StandardController controller) { this.purchaseRequisitionObj = (Cnno_Purchase_Requisition__c)controller.getRecord(); this.purchaseRequisitionObj.OwnerId = UserInfo.getUserId(); this.purchaseRequisitionObj.Status__c = '1 - Open'; } public Cnno_Purchase_Requisition__c getPurchaseRequisition() { return purchaseRequisitionObj; } public void setPurchaseRequisition(Cnno_Purchase_Requisition__c pr) { this.purchaseRequisitionObj = pr; } public Double getTotalAmount() { return TotalAmount; } public void doRefresh() { totalAmount = purchaseRequisitionObj.Item_Requested__r.Standard_Cost__c * purchaseRequisitionObj.Quanitity__c; } }

 

Will really appreciate your help! I'm blocked here.

 

Thanks!

 

Fernando.-

  • July 05, 2009
  • Like
  • 0
Hi, I'm trying to perform an approval action through APEX code, in an extended controller.  

First I do a Submit for Approval, overwriting the standard one with a visualforce custom button. Here is the code in my extended controller:

 

public PageReference submitApproval() { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); req1.setObjectId(purchaseRequisitionObj.id); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); return Page.PR_Detail_VF; }

After that event, the object left in "Pending" approval state. Then in my detail visualforce page, for specific cases, I have a "Direct Approval" button. That button should perform the instance approval changing its state to "Approved". Here is where I'm stuck, because I can not find the way to get the WorkitemId of the request. I mean the workitemId of the instance I asynchronously approved before. This is the code:

 

public PageReference directApproval() { // Instantiate the new ProcessWorkitemRequest object and populate it Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest(); req2.setComments('Direct approval by requester'); req2.setAction('Approve'); req2.setNextApproverIds(new Id[] {UserInfo.getUserId()}); req2.setWorkitemId("FROM WHERE I CAN GET THIS ID??"); // Submit the request for approval Approval.ProcessResult result2 = Approval.process(req2); return Page.PR_Detail_VF; }

 

Any cue will be highly appreciated. Many thanks in advance Fernando.-

 

  • July 14, 2009
  • Like
  • 0

Hi,

 

I'm not able to get the inputField values passed into my extended controller. Need that to do some calculations in my apex code and refresh the visualforce page to show the new calculated values to the user.

Here share the code I have up to now:

 

Visualforce code: (please see the line comments on it)

 

<apex:page standardController="Cnno_Purchase_Requisition__c" extensions="PurchaseRequisitionController" id="PR_New_page"> <apex:SectionHeader title="Purchase Requisition" subtitle="New Purchase Resquisition" /> <apex:form > <apex:pageblock title="Purchase Requisition Creation" mode="edit" id="block"> <apex:pageMessages /> <apex:pageBlockButtons location="both"> <apex:commandButton action="{!save}" value="Save"></apex:commandButton> <apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton> <apex:commandButton action="{!doRefresh}" value="Refresh Values" rerender="block"></apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection columns="2" title="Information"> <apex:outputField value="{!PurchaseRequisition.OwnerId}"/> <apex:outputField value="{!PurchaseRequisition.Status__c}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="Item Requested"/> <apex:outputPanel id="item"> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Item_Requested__c}"> <!-- apex:actionSupport event="" rerender="item" status="status"/ --> </apex:inputField> <!-- apex:actionStatus startText="applying value..." id="status"/ --> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Request_Date__c}"/> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Required_Item_Description__c}"/> <apex:outputField value="{!Cnno_Purchase_Requisition__c.Item_Requested__r.Standard_Cost__c}"/> <!-- THIS IS NOT SHOWN!! --> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Ship_To_Location__c}"/> <apex:pageBlockSectionItem > <apex:outputlabel value="Total Amount" /> <apex:outputtext value="{!totalamount}"/> <!-- This throught NULL when refresh performs --> </apex:pageBlockSectionItem> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Max_to_pay__c}" /> </apex:pageBlockSection> <apex:pageBlockSection columns="1" title="Additional Notes"> <apex:inputField value="{!Cnno_Purchase_Requisition__c.Additional_Notes__c}"/> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>

 

APEX Code in extended controller:

 

public class PurchaseRequisitionController { private Cnno_Purchase_Requisition__c purchaseRequisitionObj; private Cnno_Purchase_Items__c item; private String vendor; private Double totalAmount; public PurchaseRequisitionController(ApexPages.StandardController controller) { this.purchaseRequisitionObj = (Cnno_Purchase_Requisition__c)controller.getRecord(); this.purchaseRequisitionObj.OwnerId = UserInfo.getUserId(); this.purchaseRequisitionObj.Status__c = '1 - Open'; } public Cnno_Purchase_Requisition__c getPurchaseRequisition() { return purchaseRequisitionObj; } public void setPurchaseRequisition(Cnno_Purchase_Requisition__c pr) { this.purchaseRequisitionObj = pr; } public Double getTotalAmount() { return TotalAmount; } public void doRefresh() { totalAmount = purchaseRequisitionObj.Item_Requested__r.Standard_Cost__c * purchaseRequisitionObj.Quanitity__c; } }

 

Will really appreciate your help! I'm blocked here.

 

Thanks!

 

Fernando.-

  • July 05, 2009
  • Like
  • 0