+ Start a Discussion

Pass in current record to new VisualForce page

I have a custom object called Projects__c that track project related details (ie due dates, owners,....).  A project can have multiple cases assigned to it as well.  I have created a VisualForce page to perform a "quick case add", allowing the user to quickly add a new case for a the project they are viewing.


My challenge is that when the custom button is clicked on the projects layout to open my new quick case add VF page, I would like to pass in the current project so that I can save that with the new case they are quickly adding.  This will eliminate the step of having to search for a project on the quick add VF page.


Any suggestions (code samples) on how best to achieve this?  Via javascript or custom controller?


Here is my quick case add VF page



<apex:page standardController="case" showHeader="false" sidebar="false"> <STYLE type="text/css"> .labelCol { text-align: right } .dataCol { text-align: left } </STYLE> <apex:form > <apex:pageBlock title="Quick Add New Project Case/Task"> <table> <tr> <td><apex:outputLabel styleclass="labelCol" value="Status" for="status" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.status}" id="status" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Case Owner" for="co" /></td> <td><apex:inputField styleclass="dataCol" value="{!$User.ID}" id="co" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Client Owner" for="clio" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.contactID}" id="clio" /></td> </tr> <!-- add internal owner --> <tr> <td><apex:outputLabel styleclass="labelCol" value="Due Date" for="dd" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.Date_Du__c}" id="dd" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Internal Due Date" for="idd" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.Internal_Date_Due__c}" id="idd" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Project" for="proj" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.Project__c}" id="proj" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Subject" for="subject" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.subject}" id="subject" style="width:400px" /></td> </tr> <tr> <td><apex:outputLabel styleclass="labelCol" value="Description" for="desc" /></td> <td><apex:inputField styleclass="dataCol" value="{!case.description}" id="desc" style="width:800px; height: 100px" /></td> </tr> </table> <apex:commandButton action="{!Save}" value="Save" rerender="AJAXTest" status="AJAXStatus" /> <apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" ID="AJAXStatus" /> <!-- <apex:commandButton action="{!save}" value="Save Case" />--> </apex:pageBlock> </apex:form> </apex:page>




I can only suggest having "Projects__c" as your standardController and "case" as controller or extensions. I'm not sure if it would solve things or make them worse.
Edwin VijayEdwin Vijay

Hi ,


If you need to place the custom button on your  Projects__c page layout, you will have to use Projects__c as your standard controller. Otherwise, your visualforce page will not show up in the list of available pages.


When you do so, the id of the Project will be passed automatically.


You can retrieve the id using System.currentPageReference().getParameters().get('id') in your extension class.


Also, i believe you want to create a new case and associate it with the project.


Hope this helps..


I did place a custom button on my Project_KA__c layout page, but am calling my VF page with the JavaScript from that button (via on click)




In my VF page, I am using the case standard controller, so what I need to do is pass in the current ProejctID from my Project_KA__c object to my VF page referenced above. 


Can this be done via the JavaScript on my custom button?



Edwin VijayEdwin Vijay

Haan...If that is what you are looking for then use an URL and not javascript. With URL you can pass any parameter using merge fields.


And also, you can set window properties (height,width etc).


Also make sure you use the URL '/apex/VFpagename{your merge field}' ... hardcoding like https://na4.salesforce.com/apex will cause problems when you move your work to production.


Hope this helps