+ Start a Discussion

How do I use a passed in query string parameter in VF page?

Hello all,

I have a custom object called Projects_ka__c that holds projects.  There is a relationship to Cases, where there can be many cases to one Project.  I have a custom button on the Projects_ka__c layout that launches a VF page "addNewProjectCase" that is simply a very streamlined version of the case page, with only the fields I want completed on it.  


What I am trying to do is pass in the Projects_ka__c current record, so that on the save action of my addNewProjectsCase page I can have the project pre-populated.


The custom button that launches the VF page has the following code




My thinking is that I can pass the projectId via merge field in the query string, parse it out in the custom controller and pass the value to the VF page to use either on save, or populate a hidden field.


It almost works, I get the correct projectid passed to the VF page, but when saving I get an error telling me that the projectId is of invalid type


What am I doing wrong? Suggestions?




VF Page


<apex:page standardController="case" extensions="CaseExtension" 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="{!case.ownerID}" id="co" /></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="ProjId" /></td> <td><apex:inputField styleclass="dataCol" value="{!ProjId.q}" id="ProjId" /></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="{!mysave}" 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>

 My Custom Controller


public class CaseExtension { Case myCase; //string CaseUser; string DefaultStatus; string q; private final ApexPages.StandardController controller; public CaseExtension(ApexPages.StandardController controller){ this.controller = controller; myCase = (Case)controller.getRecord(); myCase.Status = 'Waiting'; myCase.Type = 'Project Task'; myCase.Send_Auto_Acknowledgement__c = False; } public pagereference mysave() { string projid = getProjId(); system.assert( projid != null, ' missing Proj id'); myCase.project__c=projid; insert myCase; return null; } public String getProjId() { String q = ApexPages.currentPage().getParameters().get('projid'); return q; } }


Thanks for any suggestions






is projectid a salesforce id type (15 or 18 char generated string), or is it something you define manually?  i typically see this when users are trying to put something that isn't a true sf id into an id (lookup/master detail/etc) field.
Its a field that I've added to the Case layout with a relationship to my custom object, a lookup to my custom object called Project_ka__c. 




system.debug('Case info: ' + myCase);


 right before your insert myCase statement and see what it's actually trying to write in teh fields.