简体   繁体   English

单击带有条件记录的查找图标时,打开VF页面

[英]Open VF page when clicked on lookup icon with conditional records

i am trying to get this running with some modifications. 我试图通过一些修改使它运行。 http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/ http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/

I have to get those accounts of which my contact is having contact role and account which it belongs to. 我必须获取我的联系人具有联系人角色的那些帐户及其所属的帐户。

I have written soql query and having different accounts from two ojbects. 我写了soql查询,并从两个对象拥有不同的帐户。 I saved the list as set to avoid duplicates. 我将列表保存为设置以避免重复。

my second vf page shows account names but when i select account name,in my first vf page i get this error. 我的第二个vf页面显示帐户名称,但是当我选择帐户名称时,在我的第一个vf页面中出现此错误。

Error: value '{!Cas.AccountId}' is not a valid id field Yes because i am adding value to set as set.add(variable.name); 错误:值'{!Cas.AccountId}'不是有效的ID字段是,因为我正在添加要设置为set.add(variable.name)的值; this displays account name..if i add ids,it dislays ids on vf page which user cant understand. 这会显示帐户名称。如果我添加ID,则会在用户无法理解的VF页面上显示ID。

i am struck here and cant get goin!!! 我在这里被击中,不能进去! Please guide me!!!!!! 请指导我!

Thanks in advance!!!!! 提前致谢!!!!! My second vf page and class 我的第二个vf页面和课程

    <apex:page controller="Customaccountlookupcontroller" tabStyle="Account" showHeader="false" title="Search" id="pg" sidebar="false">
     <apex:form >
         <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
    <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">

      <!-- SEARCH TAB -->
      <apex:tab label="Search" name="tab1" id="tabOne">

        <apex:actionRegion >  
          <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
            <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>
            <apex:inputText id="txtSearch" value="{!searchString}" />
              <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>
          </apex:outputPanel>

            <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
            <apex:pageBlock id="searchResults">
            <apex:pageBlockTable value="{!allaccts}" var="a"> 
            <apex:column >           
            <apex:facet name="header">
            <apex:outputPanel >Account Name</apex:outputPanel>                
            </apex:facet> 
              <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a}','{!a})', false)" rendered="{!NOT(ISNULL(a))}">{!a}</apex:outputLink>   
            </apex:column>
            </apex:pageBlockTable>
            </apex:pageBlock>
          </apex:outputPanel>
        </apex:actionRegion>

      </apex:tab>
    </apex:tabPanel>
  </apex:outputPanel>          
     </apex:form>      
</apex:page>

apex class: 顶点类:

Public with sharing class Customaccountlookupcontroller{

    Public set<string> allaccts{get;set;}
    public string searchString{get;set;}
    Public list<account> results{get;set;}
    Public string selectedkey{get;set;}

    public Customaccountlookupcontroller() {

    allaccts =  new set<string>();

  //Contact objcontact =[select accountid,(select AccountId,Account.name from AccountContactRoles) from Contact where id=:userList[0].contactId];
    Contact objContact =[select AccountId,Account.name,(select AccountId,account.name from AccountContactRoles) from Contact where Id='00317000006VtoR'];

    for(AccountContactRole obj: objContact.AccountContactRoles)
    {    
    allaccts.add(obj.account.name);
    allaccts.add(objContact.account.name);
    }
    System.debug('*******objcontact:'+allaccts);    
    }

    public PageReference search() {

    return null;
     }

   }
    public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
    }

    public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
    }   
}

Since you aren't getting an Account record back from your queries (and that is the major difference between your code and jeff's code), you'll need to create an account wrapper object. 由于您没有从查询中获得Account记录(这是您的代码与jeff的代码之间的主要区别),因此需要创建一个Account wrapper对象。 This object would be an internal class of your controller. 该对象将是控制器的内部类。

The wrapper could look like this: 包装器可能如下所示:

public class AccountWrapper {
public String name {get; set;}
public Id accountId {get; set;}

    public AccountWrapper(String name, String accountId) {
        this.name = name;
        this.accountId = accountId;
    }
}

You would then create AccountWrapper objects to use in your list on the VF page 然后,您将创建AccountWrapper对象以在VF页面上的列表中使用

for(AccountContactRole obj: objContact.AccountContactRoles) {   
    allaccts.add(new AccountWrapper( obj.account.name, obj.AccountId ));
    allaccts.add(new AccountWrapper( objContact.account.name, objContact.AccountId ));
}

Of course, you'd need to redefine your list to be used on the VF page: 当然,您需要重新定义要在VF页面上使用的列表:

Public set<Customaccountlookupcontroller.AccountWrapper> allaccts{get;set;}

Hopefully this will get you closer to your goal. 希望这将使您更接近目标。 What I would also do is simplify this example to make sure that this wrapper class is working properly for you first - then build it back up. 我还要做的就是简化此示例,以确保该包装器类首先为您正常工作-然后对其进行备份。

Don't forget to modify your VF page to accommodate the wrapper class member variable names. 不要忘记修改您的VF页面以容纳包装类成员变量名称。

UPDATE: If the list has duplicates, you can track them by storing the ids in a set and checking this set before adding to your list like so: 更新:如果列表中有重复项,则可以通过将ID存储在集合中并在添加到列表中之前检查该集合来跟踪它们,如下所示:

Set<Id> idSet = new Set<Id>();

for(AccountContactRole obj: objContact.AccountContactRoles) {   
    //prevent duplicates. Since we are using two different sObjects, we can't just add to a set to remove duplicates.
    //so we add the account ids to a set (and check this set before adding to our list)
    if (!idSet.contains(obj.AccountId)){
        allaccts.add(new AccountWrapper( obj.account.name, obj.AccountId ));
        idSet.add(obj.AccountId);
    }
    if (!idSet.contains(objContact.AccountId)){
        allaccts.add(new AccountWrapper( objContact.account.name, objContact.AccountId ));
        idSet.add(objContact.AccountId);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM