+ Start a Discussion
SFC7SFC7 

Custom component does not save object changes!

I need to customize the edit layout of several objects in a similar way using a visual force page. So, instead of create a page of every object I need with all the fields added manually, I'm trying to develop a custom component that, using SObject metadata and field sets, creates the page dinamically. So, I have a custom page per SObject like this:


<apex:page standardController="MyCustomSObject">
    <c:Translate_SObject object="{!MyCustomSObject}"/>
</apex:page>

And this is my component, first the view:

<apex:component controller="Edit_Controller" allowDML="true">
<apex:attribute name="object" type="SObject" required="true" description="Id of the object to be translated" assignTo="{!record}"/>
...
<apex:form id="form">
<apex:pageBlock id="editBlock" rendered="{!showEditBlock}">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="fieldSection">
<apex:repeat value="{!fieldList}" var="f">
<apex:inputField value="{!record[f.fieldInfo]}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:component>

And now, the controller:

public with sharing class Edit_Controller
{
public SObject record{ get; set; }
public Edit_Controller(){ }
public PageReference save(){ ApexPages.StandardController sc = new ApexPages.StandardController(record); return sc.save(); } 
}

The page shows the fields of the SObject with their expected values. I can modify these values on the page but when I press the Save button the SObject saved doesn't have any of the changes. It seems that the SObject reference used by the page it's different that the SObject reference used by the controller.

Could anyone help me? Thanks in advance.
 
ShashankShashank (Salesforce Developers) 
The standard controller actions like save will work only in controller extensions but not in custom controllers, which could be the reason here. So, instead of using the standard save action, you may have to write code for inserting/updating records and use a custom save button. I haven't tested it out though.
SFC7SFC7

Thanks your reply!

I tried with custom save as well but nothing i got.