+ Start a Discussion
Adriana Reyes 7Adriana Reyes 7 

Save Visualforce fields selection to another object?

So I have an object called Purchase Requisition that has a button that leads the user to a pop up visualforce page where they select a Warehouse from a picklist which is another custom object. The picklist is generated by all of the records in the Warehouse object. I had to do this because users don't have access to Warehouse due to the cost of licensing. I want whatever their selection is on that window and then hit save, to then save the warehouse name as a text field on the purchase requisition records that they started with. I'm not really sure how to go about that. Here is the VF page and controller that I have built so far. Any help is appreciated!
public class selectWarehouse {
    private final Purchase_Requisition__c pr;
    public selectWarehouse(ApexPages.StandardController stdController) {
        this.pr = (Purchase_Requisition__c)stdController.getRecord();
    public string selectedWarehouse{get;set;}
    public list<SelectOption> getWarehousenames() {
        List<SelectOption> options = new List<SelectOption>();
        for (Warehouse__c w : [select name from Warehouse__c order by name desc limit 100])
            options.add(new SelectOption(w.name, w.name));
        return options;
<apex:page lightningStylesheets="true" standardController="Purchase_Requisition__c" extensions="selectWarehouse" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Select A Warehouse">
            <apex:outputLabel value="Warehouse "/>
            <apex:selectList size="1">
                <apex:selectOptions value="{!Warehousenames}">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>

Dhanraj Poojary 18Dhanraj Poojary 18
You can Probably use a String with get and set to get back the selected value in Select List from the Visualforce page back to your Controller and then Perform further processing

Apex Class
String selectedWarehouseValue{get;set;}

Visualforce Page
<apex:selectList size="1" value="{!selectedWarehouseValue}">
              <apex:selectOptions value="{!Warehousenames}">

Apex Class
public void save(){
System.debug('Selected Warehouse Value'+selectedWarehouseValue);