function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishal DedaniyaVishal Dedaniya 

How to handle multiple lookup field on same object field?

Hello Experts,

I am in progress of customizing the standard partner page of salesforce due to some custom requirement

Standard Partner page:



Here each textbox fields are attached with Account Name lookup field.

Similarly when I started creating my custom Partner VisualForce page, and when i click on second look up button which is next to second textbox field and select any account name, it always update first textbox field value only. Now I am not sure how to handle multiple lookup field on same object field using VisualForce? Any help in order to resolve this issue would higly appriciated.

Page Editor Code:

<apex:page controller="webdev" tabStyle="Partner">
<apex:sectionHeader title="Partner"/>
  <apex:form >
  <apex:pageBlock title="Partner Edit">        
         <apex:panelGrid columns="5" width="30%">
                <apex:outputLabel > &nbsp;&nbsp;&nbsp; </apex:outputLabel>
                <apex:outputLabel > &nbsp; </apex:outputLabel>
                <apex:outputText value="Primary"/>
                <apex:outputText value="Partner"/>
                <apex:outputText value="Role"/>
         </apex:panelGrid>
         <apex:panelGrid columns="3" width="30%">
             <apex:outputLabel > &nbsp; </apex:outputLabel>
            
             <apex:inputField value="{!Opportunity.AccountId}" />
             <apex:selectList value="{!partnerRoles}" size="1">
            <apex:selectOptions value="{!roles}"/>
                </apex:selectList>
               
                <apex:outputLabel > &nbsp; </apex:outputLabel>
               
                <apex:inputField value="{!Opportunity.AccountId}" />
        <apex:selectList value="{!partnerRoles}" size="1">
            <apex:selectOptions value="{!roles}"/>
                </apex:selectList>
               
         </apex:panelGrid>
         <apex:facet name="footer">
            <apex:commandButton value="Save" action="{!savePartnerData}" />
        </apex:facet>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Page Controller Code:

public class webdev {
//public string partnerRoles{get;set;}
Opportunity opportunity;
String partnerRoles;

    public String getPartnerRoles () {
      return partnerRoles;
    }

    public void setpartnerRoles (String partnerRoles ) {
        this.partnerRoles  = partnerRoles ;
    }
 
   public PageReference savePartnerData() {
      PageReference opptyPage = new PageReference('http://www.google.com/?newid=' + Opportunity.AccountId);
      return opptyPage ;
   }
  
   public Opportunity getOpportunity() {
        if(opportunity == null) opportunity = new Opportunity();
            return opportunity;
    }

    public List<SelectOption> getRoles() {
          List<SelectOption> options = new List<SelectOption>();
          PartnerRole[]  partnerRole = [Select  MasterLabel from PartnerRole  where CreatedById <> null];
          options.add(new SelectOption('--None--','--None--'));
          for(Integer i=0;i<partnerRole.size();i++)
          {
              options.add(new SelectOption(partnerRole[i].MasterLabel,partnerRole[i].MasterLabel));
          }
        return options;
      }
}
Vishal DedaniyaVishal Dedaniya
I have got the solution :)

Vishal
dchasmandchasman
Vishal,

Could you please post your solution to this for other community members to learn from? I suspect your are not the only one that might be flummoxed by the same thing?

Thanks!


Message Edited by dchasman on 10-04-2008 06:33 AM
mkaspermkasper

Please post your resolution.  I am in need of the same exact solution!

 

Thanks, Mike

Ron HessRon Hess

Here is the normal method, you need a list of something

 

 

<apex:page controller="webdev" tabStyle="Partner">
<apex:sectionHeader title="Partner"/>
<apex:form >
<apex:pageBlock title="Partner Edit">

<apex:pageBlockTable value="{!apList}" var="p">
<apex:column ><apex:inputField value="{!p.opp.accountId}" /></apex:column>
<apex:column > <apex:selectList value="{!p.role}" size="1">
<apex:selectOptions value="{!roles}"/>
</apex:selectList></apex:column>

</apex:pageBlockTable>

<apex:facet name="footer">
<apex:commandButton value="Save" action="{!savePartnerData}" />
</apex:facet>
</apex:pageBlock>
</apex:form>
</apex:page>

 and the controller which holds the list, i used a new class to hold the opportunity and a string for the role

 

 

public class webdev {
public class newAP {
public Opportunity opp {get;set;}
public String role {get; set;}
public newAP() { opp = new Opportunity(); }
}
public List<newAP> apList {get; set; } {apList = new List<newAp>(); }

public webdev() {
apList.add ( new newAP() );
apList.add ( new newAP() );
apList.add ( new newAP() );
}

public PageReference savePartnerData() {
PageReference opptyPage = new PageReference('http://www.google.com/?newid=' + apList.get(1).opp.AccountId););
return opptyPage ;
}

public List<SelectOption> getRoles() {
List<SelectOption> options = new List<SelectOption>();
PartnerRole[] partnerRole = [Select MasterLabel from PartnerRole where CreatedById <> null];
options.add(new SelectOption('--None--','--None--'));
for(Integer i=0;i<partnerRole.size();i++)
{
options.add(new SelectOption(partnerRole[i].MasterLabel,partnerRole[i].MasterLabel));
}
return options;
}
}

 

 

this way each input field is bound to a seperate variable in the controller.

 

 

 

Message Edited by Ron Hess on 03-03-2009 08:30 PM
mkaspermkasper

Thanks for the quick reply Ron!

 

Just one more quick question. 

 

Since I am new with Visualforce Pages, where do I place the Controller Code at?  If its within the same page where the VP code is, what is a valid seperator between the two?

 

Sorry, trying to learn the coding part of this all.

 

Thanks again for your help.

 

Mike

mkaspermkasper

Nevermind, I figured it out.

 

Thanks again for your help Ron.

mkaspermkasper

Ron,  It seems that my situation may differ from the code previously offered.

 

Here is what I am trying to accomplish.

 

I am ultimately trying to populate a multi-picklist from a given criteria that users can select for an object.

 

For instance, we deal with churches, and I would like to automatically populate all the Catholic Churches for a user to select which would add them to the object or custom object.

 

The reason I don't want to have to manually add these churches to the picklist, is because we are adding churches on a regular basis.  So you see my dilhemma.

 

Anyway, I was previously thinking that I could add that multiple lookup Visualforce Page to the asset layout and have it pull those in.  But I cannot figure out how to accomplish this.

 

Do you have any suggestions on the best way to reach my ultimate goal?

 

Thanks again, Mike.

vandana.midha@ivanik.comvandana.midha@ivanik.com

hiiiiiii,   I want to save multiple rows of one object and also want to generate only one id for all mulituple rows. Please send me if you have any solution.

 

 

 

 

 

Thanks

Varun Gupta