You need to sign in to do that
Don't have an account?
BManojKumar
Opportunity Owner Name in Visual Force page
Dear All,
I am overriding the opportunity creation page for a particular record type using a visual force page. I would like to show the opportunity owner name in the visual force page as the standard page does. Please help me to find out the way to get the user detail who creates the opportunity.
Thanks
Manoj
Hi schreurs_jd,
Your code sounds good. But I have some business logic based on the user details. I found the way to get the user id. In my constructor I just add a code ,
public String u {get; set;}
u = Userinfo.getUserId();
Thanks
Manoj
All Answers
This is a really basic example, but should get you started.
When creating a record the owner is not set yet, unless you have also a custom controller and you set it manually. When it's only a create page and not an edit page, you can fool the system like below. I just user the merge fields for the current user, and append the correct td classes to make sure layout is maintained correctly. See also http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm
Hi schreurs_jd,
Your code sounds good. But I have some business logic based on the user details. I found the way to get the user id. In my constructor I just add a code ,
public String u {get; set;}
u = Userinfo.getUserId();
Thanks
Manoj
Hi Manoj,
Great that you got it working :) I was thinking while I was eating that my code is not perfect, since there is no support for multiple languages... Just out of curiosity, since i just started learning VF, can you also show me the VF page code you use to display the opportunity owner in your final solution?
Thanks, Jan-Dirk
Hi schreurs_jd,
Sorry for the delay in posting this.
I have posted the entire code below. Please feel free to drop a mail to me at manoj.kumar@emdiesels.com if incase any queries.
public with sharing class opportunityRedirect {
private ApexPages.StandardController controller;
public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}
public String cancelURL {get; set;}
public String ent {get; set;}
public String confirmationToken {get; set;}
public String userAccount {get; set;}
public Opportunity opp {get; set;}
public String u {get; set;}
public String pId {get; set;}
public String currencyValue {get; set;}
public String parentId {get; set;}
public User userInformation {get; set;}
public opportunityRedirect(ApexPages.StandardController controller) {
this.controller = controller;
retURL = ApexPages.currentPage().getParameters().get('retURL');
System.debug('retURL------------------------------------------->'+retURL);
rType = ApexPages.currentPage().getParameters().get('RecordType');
System.debug('rType------------------------------------------->'+rType);
cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
System.debug('cancelURL------------------------------------------->'+cancelURL);
ent = ApexPages.currentPage().getParameters().get('ent');
System.debug('ent------------------------------------------->'+ent);
confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
System.debug('confirmationToken------------------------------------------->'+confirmationToken);
saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
System.debug('saveNewURL------------------------------------------->'+saveNewURL);
parentId = ApexPages.currentPage().getParameters().get('CF00NQ0000000TOqV_lkid');
System.debug('parentId------------------------------------------->'+parentId);
userAccount = ApexPages.currentPage().getParameters().get('userId');
System.debug('userAccount------------------------------------------->'+userAccount);
u = Userinfo.getUserId();
System.debug('u------------------------------------------->'+u);
userInformation = [SELECT Account__c,ProfileId,Currency__c FROM User WHERE Id = : u];
System.debug('userInformation------------------------------------------->'+userInformation);
pId = userInformation.ProfileId;
currencyValue = userInformation.Currency__c;
opp = (Opportunity)controller.getrecord();
if(null != parentId) {
opp.Parent_Bid__c = parentId;
}
if(null != rType){
opp.RecordTypeId = rType;
}
opp.Inquiry_Number_Power_Products_Only_del__c = 'None';
opp.OpportunityCurrency__c = 'U.S. Dollar';
if(null != userInformation.Account__c){
String accId = null;
try{
accId = [SELECT Id FROM Account WHERE Name = :userInformation.Account__c limit 1].Id;
}
catch(Exception e){
System.debug('Exception-------------->'+e);
}
System.debug('accId------------------------------------------->'+accId);
if(null != accId){
opp.AccountId = accId;
}
System.debug('opportunity------------------------------------------->'+opp);
}
}
public PageReference redirect(){
PageReference returnURL;
// Redirect if Record Type corresponds to custom VisualForce page
if(null == rType || rType.equals('012Q0000000CmCZ') || rType.equals('012Q0000000CoC7')) {
if(pId.equals('00eQ0000000QJxtIAG')){returnURL = new PageReference('/apex/opportunityPage');}
else{returnURL = new PageReference('/apex/opportunityPageInternal');}
}
else {
returnURL = new PageReference('/006/e');
}
returnURL.getParameters().put('RecordType', rType);
returnURL.getParameters().put('retURL', retURL);
returnURL.getParameters().put('cancelURL', cancelURL);
returnURL.getParameters().put('ent', ent);
returnURL.getParameters().put('_CONFIRMATIONTOKEN', confirmationToken);
returnURL.getParameters().put('save_new_url', saveNewURL);
returnURL.getParameters().put('nooverride', '1');
if(null != currencyValue) returnURL.getParameters().put('00NQ0000000UjiZ', currencyValue);
returnURL.setRedirect(true);
return returnURL;
}
public PageReference cancel() {
PageReference pr = new PageReference('/006/o');
pr.setRedirect(true);
return pr;
}
}
This is the VF page for the code.
<apex:page StandardController="Opportunity" extensions="opportunityRedirect" showHeader="true">
<apex:pageBlock title="Opportunity Edit" helpTitle="Help for this page" helpUrl="/help/doc/user_ed.jsp?loc=help&target=opp_edit.htm§ion=Opportunities">
<apex:form >
<table>
<tr><td colspan="6" align="center"><apex:commandButton action="{!save}" value="Save"/><apex:commandButton action="{!cancel}" value="Cancel"/></td></tr>
<tr><td bgcolor="DDBE15" colspan="6"><font color="white"><b>Opportunity Information</b></font></td></tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.Name-_help">Opportunity Name<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Name', '{!$ObjectType.Opportunity.Fields.Name.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Name}"/></td><td width="10%"></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.CloseDate-_help">Close Date<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.CloseDate', '{!$ObjectType.Opportunity.Fields.CloseDate.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.CloseDate}"/></td>
</tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.AccountId-_help">Account Name<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.AccountId', '{!$ObjectType.Opportunity.Fields.AccountId.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.AccountId}" /></td><td></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.Ship_Date_First_Unit__c-_help">Ship Date - First Unit<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Ship_Date_First_Unit__c', '{!$ObjectType.Opportunity.Fields.Ship_Date_First_Unit__c.inlineHelpText}');</script></span> </td><td><apex:inputField value="{!Opportunity.Ship_Date_First_Unit__c}"/></td>
</tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.Inquiry_Number_Power_Products_Only_del__c-_help">Inquiry Number<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Inquiry_Number_Power_Products_Only_del__c', '{!$ObjectType.Opportunity.Fields.Inquiry_Number_Power_Products_Only_del__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Inquiry_Number_Power_Products_Only_del__c}"/></td><td></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.StageName-_help">Stage<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.StageName', '{!$ObjectType.Opportunity.Fields.StageName.inlineHelpText}');</script></span></td><td><c:stageComponent SystemEntity="Opportunity" value="{!Opportunity.StageName}" picklistField="StageName"></c:stageComponent></td>
</tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.Shipyard__c-_help">Shipyard<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Shipyard__c', '{!$ObjectType.Opportunity.Fields.Shipyard__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Shipyard__c}"/></td><td></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.Probability_Customer_Will_Order_At_All__c-_help">Probability Customer Will Order At All<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Probability_Customer_Will_Order_At_All__c', '{!$ObjectType.Opportunity.Fields.Probability_Customer_Will_Order_At_All__c.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Probability_Customer_Will_Order_At_All__c}"/></td>
</tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.Consultant__c-_help">Consultant<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Consultant__c', '{!$ObjectType.Opportunity.Fields.Consultant__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Consultant__c}"/></td><td></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.Probability_of_EMD_Being_Selected__c-_help">Probability of EMD Being Selected<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Probability_of_EMD_Being_Selected__c', '{!$ObjectType.Opportunity.Fields.Probability_of_EMD_Being_Selected__c.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Probability_of_EMD_Being_Selected__c}"/></td>
</tr>
<tr>
<td class="labelCol"><span class="helpButton" id="Opportunity.End_Customer__c-_help">End Customer<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.End_Customer__c', '{!$ObjectType.Opportunity.Fields.End_Customer__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.End_Customer__c}"/></td><td></td>
<td class="labelCol"><span class="helpButton" id="Opportunity.Probability-_help">Probability (%)<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Probability', '{!$ObjectType.Opportunity.Fields.Probability.inlineHelpText}');</script></span></td><td><apex:inputField required="false" value="{!Opportunity.Probability}"/></td>
</tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Description-_help">Description<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Description', '{!$ObjectType.Opportunity.Fields.Description.inlineHelpText}');</script></span></td><td><apex:inputTextarea cols="40" value="{!Opportunity.Description}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Product__c-_help">Product<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Product__c', '{!$ObjectType.Opportunity.Fields.Product__c.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Product__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Engine_Model_Primary__c-_help">Engine Model - Primary<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Engine_Model_Primary__c', '{!$ObjectType.Opportunity.Fields.Engine_Model_Primary__c.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Engine_Model_Primary__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Quantity_Primary__c-_help">Quantity - Primary<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Quantity_Primary__c', '{!$ObjectType.Opportunity.Fields.Quantity_Primary__c.inlineHelpText}');</script></span></td><td><apex:inputField required="true" value="{!Opportunity.Quantity_Primary__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Engine_Model_Secondary__c-_help">Engine Model - Secondary<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Engine_Model_Secondary__c', '{!$ObjectType.Opportunity.Fields.Engine_Model_Secondary__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Engine_Model_Secondary__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Quantity_Secondary__c-_help">Quantity - Secondary<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Quantity_Secondary__c', '{!$ObjectType.Opportunity.Fields.Quantity_Secondary__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Quantity_Secondary__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Target_Pricing__c-_help">Target Pricing<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Target_Pricing__c', '{!$ObjectType.Opportunity.Fields.Target_Pricing__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Target_Pricing__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Competitive_Situation__c-_help">Competitive Situation<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Competitive_Situation__c', '{!$ObjectType.Opportunity.Fields.Competitive_Situation__c.inlineHelpText}');</script></span></td><td><apex:inputTextarea cols="40" value="{!Opportunity.Competitive_Situation__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Special_Requirements__c-_help">Special Requirements<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Special_Requirements__c', '{!$ObjectType.Opportunity.Fields.Special_Requirements__c.inlineHelpText}');</script></span></td><td><apex:inputTextarea cols="40" value="{!Opportunity.Special_Requirements__c}"/></td></tr>
<tr></tr><tr></tr>
<tr><td bgcolor="DDBE15" colspan="6"><font color="white"><b>Information not shown to EMD Distributors</b></font></td></tr>
<tr></tr><tr></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Order_Release_Status__c-_help">Order Release Status<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Order_Release_Status__c', '{!$ObjectType.Opportunity.Fields.Order_Release_Status__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Order_Release_Status__c}"/></td></tr>
<tr><td class="labelCol"><span class="helpButton" id="Opportunity.Parent_Bid__c-_help">Parent Bid<img class="helpOrb" src="/s.gif" alt="" title=""/><script type="text/javascript">sfdcPage.setHelp('Opportunity.Parent_Bid__c', '{!$ObjectType.Opportunity.Fields.Parent_Bid__c.inlineHelpText}');</script></span></td><td><apex:inputField value="{!Opportunity.Parent_Bid__c}"/></td></tr>
<tr><td colspan="6" align="center"><apex:commandButton action="{!save}" value="Save"/><apex:commandButton action="{!cancel}" value="Cancel"/></td></tr>
</table>
</apex:form>
</apex:pageBlock>
</apex:page>