The command button on my Visualforce page is not saving edits to the record. Any help is appreciated!

Visualforce Pg:

<apex:page action="{!redirectToPartnerships}" extensions="EditExtensions"
    <apex:form >

        <apex:pageBlock title="Research Request Edit">
            <!--<apex:commandButton value="Save" action="{!save}"/> 
            <apex:commandButton value="Cancel" action="{!cancel}"/>  -->
            <apex:pageBlockSection title="Request Overview (Completed by 
                <apex:inputField value="{!requestRecord.Name}"/>
                <apex:repeat value="{!fields}" var="f">
                    <apex:inputField value="{!requestRecord[f.fieldPath]}"
                                     required="{!OR(f.required, f.dbrequired)}"/>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!Save}" value="Save" />
                <apex:commandButton action="{!Cancel}" value="Cancel" />



Apex Class:

public class EditExtensions {

    public string getRequestId { get; set; }
    public PartnershipRequest__c requestRecord { get; set; }
    public pageReference redirectReference;

    public yc_PartnershipEditExtensions(ApexPages.StandardController controller) {
        requestRecord = (PartnershipRequest__c) controller.getRecord();
        this.getRequestId = ApexPages.CurrentPage().getparameters().get('Id');
        this.requestRecord = getRequest();
        this.redirectReference = null;
        //  requestRecord = [select DataTool__c, Agency__c, Client__c,
        Description__c, DesiredDueDate__c, PriorityRanking__c, ImpactCategory__c
        from PartnershipRequest__c where id=:getRequestId];

    private PartnershipRequest__c getRequest() {
        String query = 'SELECT ';
        for (Schema.FieldSetMember f : this.getFields()) {
            query += f.getFieldPath() + ', ';
        query += 'Id, Name FROM PartnershipRequest__c WHERE id=:getRequestId';
        //query += this.getRequestId;
        return Database.query(query);

    public List<Schema.FieldSetMember> getFields() {
        Map<String, Schema.RecordTypeInfo> recordTypeMap =
        System.debug('reqrec' + this.requestRecord);
        if (this.requestRecord.RecordTypeId == recordTypeMap.get('General Request').getRecordTypeId()) {
            //general request
            return SObjectType.PartnershipRequest__c.FieldSets.General_Request.getFields();
        } else if (this.requestRecord.RecordTypeId ==
                recordTypeMap.get('Troubleshooting Data Vendors').getRecordTypeId()) {
            //troubleshooting data vendors
        } else if (this.requestRecord.RecordTypeId ==
                recordTypeMap.get('Sandbox').getRecordTypeId()) {
            return SObjectType.PartnershipRequest__c.FieldSets.Sandbox.getFields();
        } else if (this.requestRecord.RecordTypeId == recordTypeMap.get('Partnerships').getRecordTypeId()) {
            //if field type is partnerships, use existing VF pages for Create / Edit / View (making the return below invalid. There are no field sets being used here.)
            System.Debug('is this working?');
            //redirectReference = redirectToPartnerships();
            return SObjectType.PartnershipRequest__c.FieldSets.Troubleshooting_Data_Vendors.getFields();

        return SObjectType.PartnershipRequest__c.FieldSets.Troubleshooting_Data_Vendors.getFields();

    public PageReference redirectToPartnerships() {
        Map<String, Schema.RecordTypeInfo> recordTypeMap =
        if (this.requestRecord.RecordTypeId ==
                recordTypeMap.get('Partnerships').getRecordTypeId()) {
            system.debug('redirect to partnerships');
            PageReference redirectRef = new

                    id=' + this.getRequestId);
            return redirectRef;

        return null;
  • Wnich command? What do you mean by "no saving"? Are there errors? We need details... Apr 17, 2019 at 21:37
  • can you add an <apex:pageMessages/> tag to your page? It should surface any errors that might be thrown by the standard controller Apr 17, 2019 at 21:41
  • no errors, when I update a field and click the "Save" button, the changes are not committed.
    – FWSFDC
    Apr 17, 2019 at 21:41
  • See my 2nd comment above.... Apr 17, 2019 at 21:42
  • 1
    @SebastianKessel Don't worry, I got this one. Give me a min.
    – sfdcfox
    Apr 17, 2019 at 21:43

1 Answer 1


The "save" function you're using is attached to the StandardController. However, the record you're attaching everything to is not the record in the standard controller. Your problems start here:

    requestRecord = (PartnershipRequest__c) controller.getRecord();
    this.getRequestId = ApexPages.CurrentPage().getparameters().get('Id');
    // This is **not** from the standard controller
    this.requestRecord = getRequest();

Instead, you'll want to build your query and copy the values from the query to the standard controller record, or use the addFields method to load the necessary data.

public yc_PartnershipEditExtensions(ApexPages.StandardController controller) {
    String[] fields = new String[0];
    for (Schema.FieldSetMember f : this.getFields()) {
    // This is not legal in unit tests, so skip...
    if(!Test.isRunningTest()) {
    // now load record...
    requestRecord = (PartnershipRequest__c) controller.getRecord();
    getRequestId = requestRecord.Id;

Everything else should be okay from here.

  • I've tried updating the class with you code snippet and receive the following error: SObject row was retrieved via SOQL without querying the requested field: PartnershipRequest__c.Name
    – FWSFDC
    Apr 18, 2019 at 15:31
  • @FWSFDC Because of how your VF is written, you'll need to also add the Name field.
    – sfdcfox
    Apr 18, 2019 at 15:36
  • Not sure I follow? Where would the Name field have to be specified in the Visualforce page@ @sfdcfox
    – FWSFDC
    Apr 19, 2019 at 13:19
  • @FWSFDC You can just add the Name field to the fields list.
    – sfdcfox
    Apr 19, 2019 at 15:26
  • do you mean add the Name field to the field set? there is no fields list in the VF page or Apex Class @sfdcfox
    – FWSFDC
    Apr 21, 2019 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.