You need to sign in to do that
Don't have an account?
How to pass the parameters from Visualforce to Apex Class
I do have a page with /apex/AccountPrioritySort?id={!Account_Plan__c.Id}&type=AP. Please find my code as below
Visual Force Page
<apex:page standardController="Account_Plan__c" extensions="accountprioritysort1" tabStyle="Account" id="thePage"> <apex:form id="theForm" > <apex:pageBlock title="Editing Top 5 Account Priorities" mode="edit"> <apex:messages /> <apex:pageBlockButtons location="top"> <apex:commandButton value="Update Sorted Account Priorities" action="{!SaveAction}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!actPList}" var="item"> <apex:column value="{!item.Account_Priorities__c}"/> <apex:column headervalue="# (Top 5 Priorities)"> <apex:inputField value="{!item.Field1__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
APEX Class
public with sharing class accountprioritysort1 { public ApexPages.StandardController stdController {get; set;} public Account_Plan__c AccPri { get; set; } public list<Company_Priorities__c> actPList { get; set; } public integer aField { get; set;} public accountprioritysort1 (ApexPages.StandardController stdController){ System.debug('Is it in the Constructor'); this.stdController = stdController; this.AccPri = (Account_Plan__c)this.stdController.getRecord(); actPList = [select Field1__c,Account_Priorities__c from Company_Priorities__c where Account_Plan__c =: AccPri.Id ORDER BY Field1__c ASC ]; } public PageReference SaveAction(){ update actPList; PageReference page = new PageReference('/apex/AccountPrioritySort?id='+AccPri.id); page.setRedirect(true); return page; } public PageReference CancelAction(){ PageReference page = new PageReference('/apex/AccountPrioritySort?id='+AccPri.id); page.setRedirect(true); return page; } }
/apex/AccountPrioritySort?id={!Account_Plan__c.Id}&type=AP
Now i want to pass this
1. The value (which is as type=AP) from the Parameter Type in the Apex Controller
2. How can render by using the type variable to between Account Priorities and Risk in the VF page and Controller. This type should be used to decide what data needs to be saved i.e. should the risk code execute or Account priorities code execute.
Can any one help on this code.
Please see below updated visualforce page code:
Visualforce page:
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
All Answers
Try to use following code. you will get more idea.
Visualforce Page:
Apex Class: Let me know if you have any question on this. Please mark this "Solved" if it helps.
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Hi Hitesh,
Thank you this worked, But the Type is displayed on the Visualforce Page. I do have 2 pageblocks one for AP (type) other for (RS) type. So I should be able to render using the type variable to between Account Priorities and Risk in the VF page and Controller. This type should be used to decide what data needs to be saved i.e. should the risk code execute or Account priorities code execute.
Can you help me with this code.
Hi Hitesh,
How can add the value of strType in the URL /apex/AccountPrioritySort?id='+AccPri.id after the ID is displayed.
Please see below updated visualforce page code:
Visualforce page:
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
see below Apex Class:
Hi Hitesh,
As you are hardcoded the value &type=RS and &type=AP in both Save and Cancel actions. Would it not cause any issue.
1. In this below code update actPList is updating the value but remaining on the same page. It should Save with Database.SaveResults are return to the previous page with Text msg as SUCCESS or FAILURE.
2. I should be able to render the page blocks with , where i am writing both Account Priorities and Risks in the same Apex Class and Visual Force Page. Can you please help me render the blocks using the type. So that based on the type it should excecute that query and visual force page code.
My Visual Force Page
Partial Apex Class Page
Can you please check the below part on the APEX Code fo SaveAction. Requirement is that it should update the record values based on the strType and return back to the page and display error messages too.
The Complete APEX Class File