2012-11-01 30 views
0

我对使用Visualforce和Salesforce非常新,因此请耐心等待...我自学自学如何通过复制表单来构建Visualforce页面,以便我们的销售代表用于记录收到的订单。我很难搞清楚如何做一些(可能)非常基本的事情,我希望有人能帮助我指出正确的方向。我发现了很多关于如何做我想要的东西或类似的东西,但不是我想找的东西的说明,这让我非常困惑,为了实现这个特定的目标需要做些什么工作。显示与查找字段相关的值

这是我到目前为止已经完成了...

我建立了我的网页上查阅字段,允许用户填充的销售代表是谁(使用用户对象)。我有点困惑,为什么我提供了一个文本框和一个搜索按钮,而不是只提供一个下拉框的代表从中选择,但我想这不是在这里也不存在...

<apex:page standardController="Order__c" extensions="OrderNewExtension"> 
<apex:actionRegion > 
    <apex:inputField value="{!Order__c.User__c}" required="true" id="userID"> 
     <apex:actionSupport event="onchange" reRender="salesRepDetails" /> 
    </apex:inputField> 
</apex:actionRegion> 

<apex:outputPanel id="salesRepDetails" rendered="true"> 
    <table border="0" cellspacing="0" cellpadding="5" width="75%" style="border: 1px solid magenta;"> 
     <tr> 
      <td colspan="2" width="50%">&nbsp;</td> 
      <td><apex:outputLabel value="Phone: " for="repPhone" /></td> 
      <td class="data">***Something needs to go here***</td> 
     </tr> 
     ... 
    </table> 
</apex:outputPanel> 

我愿意做这个两件事情 -

1)用户选择后,销售代表是的,我想选择的rep的电子邮件和电话号码显示。 2)(sorta可选)我希望这个字段预填充当前用户的名称和数据,这样,代表只需要查看代表是我们的某个支持人员正在输入为别人。这有意义吗?

我不确定还有什么需要帮助我的人,但是如果在我的权力范围内,我会这样做。

回答

3

控制器:

public with sharing class yourController 
{ 
    // Defining objects 
    public User selectedUser { get; set; } 
    public Order__c order { get; set; } 

    // Constructor where the user data will be pre-populated 
    public yourController() 
    { 
     order = new Order__c(); 
     order.User__c = UserInfo.getUserId(); 
     selectedUser = [ Select Id, Email, Phone From User Where Id = :UserInfo.getUserId() ]; 
    } 

    // Method for reading selected user data 
    public pageReference readUser() 
    { 
     selectedUser = [ Select Id, Email, Phone From User Where Id = :order.User__c ]; 
     return null; 
    } 
} 

Visualforce页:

<apex:outputPanel id="userDetails"> 
    <apex:pageBlock> 
     <apex:pageBlockSection columns="1"> 
      <apex:inputField value="{!order.User__c}"> 
       <apex:actionSupport event="onchange" action="{!readUser}" reRender="userDetails"/> 
      </apex:inputField> 
      <apex:outputField value="{!selectedUser.email}"/> 
      <apex:outputField value="{!selectedUser.phone}"/> 
     </apex:pageBlockSection> 
    </apex:pageBlock>  
</apex:outputPanel> 
+0

这是否会在我的页面上工作,因为我试图制作自定义的“新订单”页面?这看起来像是特定于细节显示页面... – Lisa

+0

为什么不呢?这可以在salesforce上随时随地使用。 – mast0r

+0

对不起,我还是销售队伍的新手。我给它一个镜头,并让它工作。感谢您的帮助,我真的很感激! – Lisa