+ Start a Discussion
MC2014MC2014 

getting the value from a prefilled inputField.

In my apex, when a contact look up field is selected, it does a query and fill in the in corresponding visual force page inputfield on the form.

When I hit the save button, those field don't get saved,  however, the other fields like descpription do.  Am I left only  to using getter/setters to capture that data in Apex?

Here is the code.

<apex:page standardcontroller="Case" extensions="Internal">
    <apex:form >
    <apex:pageMessages id="msgs"/>
        <apex:pageBlock title="My Content">
            <apex:actionRegion >    
                <apex:pageBlockSection id="Shipto" title="Ship To Information">    
                    <apex:outputField value="{!case.Ship_To_Account__c}"/>       
                    <apex:inputField value="{!case.ShipToContact__c}">
                        <apex:actionSupport event="onchange" action="{!ShipToPopulated}" rerender="Shipto, msgs"/>
                    </apex:inputField> 
                    <apex:inputField value="{!case.Shipping_Address__c}"/> 
                    <apex:inputField value="{!case.ShippingCity__c}"/> 
                    <apex:inputField value="{!case.ShippingState__c}"/> 
                    <apex:inputField value="{!case.ShippingPostalCode__c}"/> 
                    <apex:inputField value="{!case.Shipping_Country__c}"/>                                                
                </apex:pageBlockSection>
            </apex:actionRegion>
            <apex:pageBlockSection title="My Content Section2" columns="1">
                <apex:inputField value="{!case.Description}" style="width: 90%; min-height: 100px" label="Special Instructions:"/>    
                <apex:outputPanel layout="block" style="align: center">
                    <apex:commandButton action="{!save}" value="Submit" style="align: center;"/>
                </apex:outputPanel>

            </apex:pageBlockSection> 
        </apex:pageBlock>
    </apex:form>
</apex:page>

public with sharing class Internal {
...
    public InternalFurfillment(ApexPages.StandardController controller) {
        this.caseObject = (Case) controller.getRecord();
    }

....

    public PageReference save(){
     // a bunch of logic.. but ultimately
     insert caseRecord;
     return null;
    }

....
//function where I populate those fields.
 public void ShipToPopulated() {
     
         Contact con = [select c.AccountId, c.Account.Name, c.MailingStreet, c.MailingState, c.MailingPostalCode, c.MailingCity, c.MailingCountry from Contact c where id=:caseObject.ShipToContact__c];
         
         caseObject.Ship_To_Account__c = con.AccountId;
         caseObject.Shipping_Address__c = con.MailingStreet;
         caseObject.ShippingCity__c = con.MailingCity;
         caseObject.ShippingState__c = con.MailingState;
         caseObject.ShippingPostalCode__c = con.MailingPostalCode;
         caseObject.Shipping_Country__c = con.MailingCountry;
     }


Best Answer chosen by MC2014
James LoghryJames Loghry
No, you should be able to get this to work pretty easily.
Have you debugged your code much?  Is the "ShipToPopulated" method getting called?  Is the query returning any results?  What's the result of caseObject after your logic runs in that method?  Also I notice that "line 39" is insert caseRecord and not insert caseObject.. is this just a typo from you pasted your code into this question?

If you find that you're having issues calling ShipToPopulated, you could probably get rid of the action function in your visualforce page and add the query / Shipping logic into your save method if that helps.

All Answers

James LoghryJames Loghry
No, you should be able to get this to work pretty easily.
Have you debugged your code much?  Is the "ShipToPopulated" method getting called?  Is the query returning any results?  What's the result of caseObject after your logic runs in that method?  Also I notice that "line 39" is insert caseRecord and not insert caseObject.. is this just a typo from you pasted your code into this question?

If you find that you're having issues calling ShipToPopulated, you could probably get rid of the action function in your visualforce page and add the query / Shipping logic into your save method if that helps.
This was selected as the best answer
Avidev9Avidev9
Whenever I see question like this , Mostly the case is you have some required field in the layout. Can you enclose the actionSupport inside a actionRegion ?
Something like

<apex:actionRegion>
    <apex:inputField value="{!case.ShipToContact__c}">
        <apex:actionSupport event="onchange" action="{!ShipToPopulated}" rerender="Shipto, msgs" />
    </apex:inputField>
</apex:actionRegion>