+ Start a Discussion
Dilan Srilal 3Dilan Srilal 3 

Visualforce Component Saving a modified record

Hi,
I have a visualforce component, in which I bind several attributes of an object.
In the component controller I have a method to upsert the modified record.
But my controller does not get the changed values, it always upsert my record with the old values. ( I dont get any exceptions)
Please kindly advise what I'm missing. Thanks.

My Component
<apex:component controller="RevenueComponent_Controller" allowDML="true">
   <apex:attribute name="revenueRecord" description="Revenue Record."
                    type="Revenue__c" required="true" assignTo="{!revenue}"/>
   <apex:form >
        <apex:pageBlock mode="mainDetail" title="" id="revenueDetail">           
                         
            <apex:pageBlockButtons location="Top" >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!saveRevenue}" id="saveButton" value="Save Revenue" reRender="recordDetails"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>
            
            
            <apex:pageBlockSection id="recordDetails" title="" columns="2">       
                <apex:inputField value="{!revenue.Year__c}"/>
                <apex:inputField value="{!revenue.Month__c}"/>         
                <apex:inputField value="{!revenue.Forecast_Amount__c}"/>
                <apex:inputField value="{!revenue.Actual_Amount__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:component>

Component Controller
public class RevenueComponent_Controller {
    public Revenue__c revenue;    
    
    public Revenue__c getRevenue(){
        return revenue;
    }
    
    public void setRevenue(Revenue__c r){
        revenue = r;        
    }
    
    public void saveRevenue(){
        System.debug('Revenue ::: ' + revenue);        
        upsert revenue;
    }
    
    public void edit(){
        
    }
}

My VF page in which the component is located.
...
        <apex:pageBlockSection title="Revenue List For FY 2016" columns="1">
            <apex:repeat value="{!projectRevenues}" var="revenue">
            
            <c:Revenue revenueRecord="{!revenue}" />
            
            </apex:repeat>
        </apex:pageBlockSection>

...


 
deepak balur 19deepak balur 19
All your variables need a get set defined according to me. Public Date Year__c {get;set} along these lines for the other variables as well. I am tempted to say saveRevenue also needs some modification but can you try with the above and see please.