You need to sign in to do that
Don't have an account?
smagee13
How do I populate a VisualFoce page with current system user
I have a VisualFoce page that I've created to perform a quick case add function. This page is called from a custom object, via button, called Projects__c. What I would like to do is save my new cases with the userID of the user who is logged in.
Can I use the UserInfo.getUserId() method directly in VF or do I need a controller extension to do this? If so, how do I return the value from the class to the VF page?
Thanks
$User
All Answers
$User
Thanks for the pointer but I still seem to be stuck. I believe that it is because Im using the Case standard controller in my VisualForce page to create a new case. All I want to do is grab the current user and use that value in the "Case Owner" field when I save the record.
Any ideas?
<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>
Exactly.. You have to use an extension to achieve your bit...
When you click on the save button call a method in the extension class...
Use Userinfo().getuserId() and assign it to ownerId...
Hope this helps.......