function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yespeeyespee 

Submit lead from a visual force screen

Is it possible to mimic 'Submit Lead' button on a visual force page? Not sure if this question was asked before. Searched the forums could not find anythign. 

 

To give a background, I created a visual force wizard that creates new leads. We also have a lead approval process on leads object. I wanted the users to be able to either save the lead or submit it for approval in the final screen of the wizard. I am kind of stuck with the submit part.Appreciate any help on this. 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
yespeeyespee

Thank you aalbert. This was very helpful. One further question on this.

 

I am writing this code in a controller instead of  a trigger. How to specify which approval process to call in case of multiple approval process exist on leads object. Here is part of my code. 

 

 

public PageReference save() { lead.company = Customer.Name; lead.customer__c = Customer.id; lead.street= Customer.BillingStreet; lead.City= Customer.BillingCity; lead.State= Customer.BillingState; lead.Country= Customer.BillingCountry; lead.postalcode = Customer.billingpostalcode; lead.website=Customer.website; lead.status='Draft'; lead.lastname='test lastname'; Insert lead; Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setObjectId(lead.id); // Submit the approval request for the lead Approval.ProcessResult result = Approval.process(req1); // Navigate to the detail page for PageReference leadPage = new PageReference('/' + lead.id); leadPage.setRedirect(true); return leadPage; }

 


 

 

All Answers

aalbertaalbert

Yes, you can automate the submission or approval processes in Apex. And just invoke that apex from a VF commandButton or commandlink, ect.

 

Here are the Apex docs.

 

 

yespeeyespee

Thank you aalbert. This was very helpful. One further question on this.

 

I am writing this code in a controller instead of  a trigger. How to specify which approval process to call in case of multiple approval process exist on leads object. Here is part of my code. 

 

 

public PageReference save() { lead.company = Customer.Name; lead.customer__c = Customer.id; lead.street= Customer.BillingStreet; lead.City= Customer.BillingCity; lead.State= Customer.BillingState; lead.Country= Customer.BillingCountry; lead.postalcode = Customer.billingpostalcode; lead.website=Customer.website; lead.status='Draft'; lead.lastname='test lastname'; Insert lead; Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setObjectId(lead.id); // Submit the approval request for the lead Approval.ProcessResult result = Approval.process(req1); // Navigate to the detail page for PageReference leadPage = new PageReference('/' + lead.id); leadPage.setRedirect(true); return leadPage; }

 


 

 

This was selected as the best answer