+ Start a Discussion
harshad kokateharshad kokate 

insert values from one object to other object in Multiselect Picklist In Visualforce Page

I am using multiselect picklist package from Github I also linked two lists for left and right to display selected and unselected lists 
But now what I need to do is I am fetching and list of picklist values of account and on add button of multiselect picklist I want to insert it to a cusotm setting object with its(Picklist) Name and Api Name all code is redy with me The problem i am facing is when i click that picklist value and add it to the right it shows that its adding in to right (selected list) but it doesnt add it to the custom setting can anyone help me out here?
 
<c:MultiselectPicklist leftLabel="Available Fields" leftOptionsNm="{!SobjectsFields}"  rightLabel="Selected Fields" rightOptionsNm="{!selectedFields}" size="5" width="300px"/>
                                            </apex:pageBlock>

///This is visual force page code where data goes to picklist controller and picklist will adjust it to either select and unselect 

///below is controller function which will insert data in to custom setting object
public PageReference UpdateCustomSetting() {
        try {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'calling After Add button Click'+sobjectsFields));
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'calling After Add button Click'+selectedFields));
            return null;
            selectedFields.add(SelectField);
            OneClickUpdatePicklistConfiguration__c tempCustomSetting = new OneClickUpdatePicklistConfiguration__c();
            String csName = SelectObject + ':' + SelectField;
            List<OneClickUpdatePicklistConfiguration__c> OCupdate=new List<OneClickUpdatePicklistConfiguration__c>([select id,PicklistFieldAPI__c, Name, sObject_API_Name__c, Field_API_Name__c, Field_API_Name_without_Namespace__c from OneClickUpdatePicklistConfiguration__c where sObject_API_Name__c =:SelectObject ]);
            mapObjectToFields = new map < String, set < string >> ();
            for(SelectOption sf : selectedFields){
                tempCustomSetting.Name = csName.length() > 38 ? csName.substring(0, 37) : csName;
	            tempCustomSetting.sObject_API_Name__c = SelectObject;
	            tempCustomSetting.Field_API_Name__c = sf.getlabel();
	            tempCustomSetting.PicklistFieldAPIWithoutPrefix__c=sf.getValue();		            
	            tempCustomSetting.Sobject__c = SelectObject;
	            tempCustomSetting.PicklistFieldAPI__c = sf.getlabel();
               	system.debug('>>>>' +tempCustomSetting.PicklistFieldAPI__c);
            }
		if (tempCustomSetting != null) {
			insert tempCustomSetting;
			return null;
		}else{
			update tempCustomSetting;
			return null;
		}
             
        }catch (System.DmlException e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDMLMessage(0)));
            return null;
        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
            return null;
	    }
    }

 
SarfarajSarfaraj
Hi Harshad,

First of all you have a return statement at line 11. This will prevent execution of rest of the lines. Please remove it,
return null;

Next problem what I can see is the variable 'OCupdate' never being used. Seems to me you have written it for the update operation at line 30. Also I can see from your code that there is a lot of unimplemented operations. But I believe you will be able to implement them once it works for the first time. 

Let me know if you need anything else.

--Akram