+ Start a Discussion

Standard Approval process button in visualforce

Hi All ,

I have a requirement to use standard aproval process functionality in visualforce page . For that I used Standard controller and showed the detail page using apex:detail tag which shows the approval process button .

But when I click on the button , it is redirecting to detail record page , Instead I need it to remain in same visualforce page where the button is clicked and showing alert box saying record is sent for approval .
Please note that I dont want to use custom approval process with apex 
Can anyone help me here?
Hi Sanju,

You can invoke the approval process from the Approval Class (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_approval.htm).

Here is the snippet for your reference:

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

public PageReference sumbitForApproval(){
		Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
		req.setComments('Submitting request for approval'); // You can make comments dynamic
		Approval.ProcessResult result = Approval.process(req);
	catch (Exception ex){
		System.debug('Exception caught');
	//return submitPageRef;
	return null;

Please upvote and mark this answer as solved, if it helped you.
Ajinkya Deshmukh
Umar Mohammad 12Umar Mohammad 12
whats that pagereference is ? How should I use standard approval process for satndard controller. a basic simple example would be appriciated.