+ Start a Discussion
vibrationvibration 

is it possible to save Picklist values in a Look Up Field?

hi
 
is it possible to save Picklist values in a Look Up Field?
 
I want to save multiple (picklist) values in a LoopUp field.
 
Objects- Item relation
 
NameText(80)
child_item__cLookup(Item relation)
parent_item__cLookup(Item relation)
 
my VFCODE code:
 

<apex:page controller="CreateMulItem" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save Task" action="{!Save}" />
</apex:pageBlockButtons>

<apex:commandButton value="Save" action="{!Save}" />
</apex:pageBlockButtons> -->
<apex:pageBlockSection title="Create Items" >

<apex:outputLabel Value="Item Name" style="margin-left:10%;position:relative;top:10px;font-weight:bold" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<apex:selectList value="{!ItemTemp}" size="1" >

<apex:selectOptions value="{!Itemname}"/>

</apex:selectList>
</apex:outputLabel>

</apex:pageBlockSection>



<apex:outputlabel value="Create New Item" for="newval" style="margin-left:4%;position:relative;top:20px;font-weight:bold" />
<apex:inputText value="{!newpicklistvalue}" id="newval" style="margin-left:4%;position:relative;top:15px;font-weight:bold" />
<apex:commandbutton action="{!saverec}" value="Add Item!" style="margin-left:4%;position:relative;top:15px;font-weight:bold" />



<apex:pageBlockSection title="Add parent and child Item">
<apex:outputLabel Value="Parent Items" style="margin-left:10%;position:relative;top:10px;font-weight:bold" >
<apex:selectList value="{!ParentTemp}" size="3" multiselect="true" >
<apex:selectOptions value="{!ParentItem}"/>
</apex:selectList>
</apex:outputLabel>

<apex:outputLabel Value="Child Items " style="margin-Right:1%;position:relative;top:10px;font-weight:bold" >
<apex:selectList value="{!ChildTemp}" size="3" multiselect="true" >
<apex:selectOptions value="{!ChildItem}"/>
</apex:selectList>
</apex:outputLabel>
</apex:pageBlockSection>

</apex:pageBlock>


</apex:form>
</apex:page>

 

class:

 

public with sharing class CreateMulItem{


// Declare variables

public String ParentTemp { get; set; }
public String ChildTemp { get; set; }
public String ItemTemp{get; set;}






// Load Parent Items
public List<SelectOption> getParentItem() {
List<SelectOption> options = new List<SelectOption>();

for(Item_relation__c Itemrelation :[Select id,Name,parent_item__c,child_item__c from Item_relation__c ]){
options.add(new SelectOption(Itemrelation.id,Itemrelation.name));
}
return options;
}

// Load Child Items
public List<SelectOption> getChildItem() {
List<SelectOption> options = new List<SelectOption>();
// options.add(new SelectOption('--None--','--None--'));
for(Item_relation__c Itemrelation :[Select id,Name,parent_item__c,child_item__c from Item_relation__c ]){
options.add(new SelectOption(Itemrelation.id,Itemrelation.Name));
}
return options;
}
// Load Child Items
public List<SelectOption> getItemname() {
List<SelectOption> options = new List<SelectOption>();
// options.add(new SelectOption('--None--','--None--'));
for(Item_relation__c Itemrelation :[Select id,Name,parent_item__c,child_item__c from Item_relation__c where Name != 'None' ]){
options.add(new SelectOption(Itemrelation.id,Itemrelation.Name));
}
return options;
}
public String newpicklistvalue{get; set;}

public void saverec()
{
Item_relation__c newrec = new Item_relation__c(name = newpicklistvalue);

insert newrec;
newpicklistvalue=NULL;
}

// Save Item Relations
public List<Item_relation__c> saverelations {get; set;}

public PageReference Save() {

Item_relation__c Sitems = new Item_relation__c();

Sitems =[select id,name, parent_item__c,child_item__c from Item_relation__c where id =: ItemTemp];


Sitems.parent_item__c = ParentTemp;
Sitems.child_item__c = ChildTemp;
update Sitems;

PageReference parrec = new PageReference('https://ap1.salesforce.com/a0A/o');
parrec.setRedirect(true);
return parrec;
}

}

 
Regards,
Azar
EDGE_XEDGE_X

You mean Making a picklist a lookup field? 

 

if that is the case, if you are on EE or UE then you can use the ApexDataLoader to do a lot of the heavy lifting for you.  

 

Now with that being said, there is still going to be a little bit of Admin-ish/Develoer-ish stuff that needs to be done.  But if I can figure this stuff out, then pretty much anyone (and probably a few of the higher order of Primates) can do it. 

 

  • What you need to do is create a custom Object (what you're doing is creating a new "type" of Record on your Salesforce).  This new custom object is basically going to become your new Lookup/Picklist. 
  • On your new custom object you're going to create a new field that will house the picklist value (just 1 value per record).  
  • Using MS-Excel create a file that has all of your current picklist values (make sure you save the file in ASCII-CSV format).
  • Using the ApexDataLoader upload your file using the "Insert" option to create new records with your picklist values (you should have 1 new record for each picklist value). 
  • When your upload is done there should be a "Success" file in your Upload Reports folder (this is usually in the same folder as the ApexDataLoader).  This file will contain not only your picklist values from your upload file, but also the Record ID of the new records that hold each value. 
  • Next create a Lookup field to replace your picklist field, and link the lookup field to your new custom object.
  • Now either run a report or use the ApexDataLoader to get the list of all your records that have the old picklist field (make sure you get the Record ID) and export this to Excel. 
  • Using the VLOOKUP function in Excel match your old picklist value to the ID of the corresponding record on your new custom object.  Once you're done save the file ASCII-CSV format.  
  • Using the ApexDataLoader upload this file using the "Update" option to point your new Lookup Field to the ID of the picklist value. 
  • Run a report the displays your old Picklist field and your new Lookup field, they should match 100%.  If they do you can remove your old picklist field and delete it. 

 

let me know if this works, or if you have any questions.     

SFFSFF

You can't. You need to use a picklist (multi-select) field to store multiple picklist values.

 

If you want to store multiple lookup values, you can either create multiple lookup fields - which I don't recommend - or a child object and related list.

 

Hope this helps,