0

I tried searching for a solution before posting it here but no luck. I have a VFP with account fields and custom InputText field which is used to capture "Other" value which is concatenated(some string manipulations) to store on a field. However, i'm unable to get the edited values back to controller in order for the save to happen as i'm using inlineeditsupport. I know one way this is possible is to use a wrapper class to capture the individual values. However i'm trying to achieve without using the wrapper if possible. Please share your inputs. Thanks you!

Controller:

public with sharing class MoreFieldsUpdate_AC{
public String testValue { get; set; }
public String accId { get; set; }
public Account acc { get; set; } 

public MoreFieldsUpdate_AC(ApexPages.StandardController controller){
    acc = (Account)controller.getRecord();
    system.debug('acc----'+acc.Id);
    testValue = '';
    /*accId = ApexPages.CurrentPage().getparameters().get('acId');
    if(String.isNotBlank(accId))
        acc = [SELECT Id, Name, Beachhead_Attributes__c, Pain_points_with_alternative__c, Benefit_Sought__c, Estimated_Budget__c, Estimated_Campaign_Timing__c, Prospect_s_target_audience_s__c, Exposure_to_TV_Ad__c,Attendees__c, Customer_Segmentation__c, Account_Status__c, Activity_Type__c, Meeting_Type__c, Primary_Lead_Source__c, Campaign__c, Discovery_Meeting__c, Pre_Meeting_Brief__c, Due_Date__c, SM_Presentation__c FROM Account WHERE Id =: accId];
    else
        acc = new Account();*/
}

/*public pageReference save(){
    system.debug('This is not----'+acc.Benefit_Sought__c);
    update acc;
    return null;
}*/
public pageReference cancel(){
    return null;
}

}

VFP:

<apex:page standardController="Account" extensions="MoreFieldsUpdate_AC" sidebar="false" showHeader="false" lightningStylesheets="true">
    <style>
        .multiSelectPicklistRow select {
            max-width: 300px;
        }
    </style>

    <apex:form id="formId">
    <apex:pagemessages escape="false"/> 
    <apex:slds />
    <div style="text-align: center"><br/><br/>
        <apex:commandButton action="{!save}" id="saveButton" value="Save" status="status" rerender="formId" rendered="true" styleClass="buttonStyle" style="background:LightBlue;width:150px;"/>&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:commandButton action="{!cancel}" id="cancelButton" value="Cancel" rendered="true" styleClass="buttonStyle" style="background:LightBlue;width:150px;"/>
    </div>

    <apex:sectionHeader subtitle="{!acc.Name}"/>
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:outputField value="{!acc.Beachhead_Attributes__c}" title="Beachhead Attributes">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Pain_points_with_alternative__c}" title="Pain points with Alternative">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Benefit_Sought__c}" title="Benefit Sought">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Estimated_Budget__c}" title="Estimated Budget">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Estimated_Campaign_Timing__c}" title="Estimated Campaign Timing">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Prospect_s_target_audience_s__c}" title="Prospect Target Audience">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Meeting_Type__c}" title="Meeting Type">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Primary_Lead_Source__c}" title="Primary Lead Source">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Campaign__c}" title="Campaign">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!acc.Discovery_Meeting__c}" title="Discovery Meeting">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                        hideOnEdit="editButton" event="ondblclick"
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:inputText style="width: 200px;" value="{!testValue}">
                   <apex:outputLabel styleClass="labelCol vfLabelColTextWrap"><!--This is from Inspect Element-->
                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                   Benefit Sought (Other)
                   </apex:outputLabel>&nbsp;&nbsp;&nbsp; 
                </apex:inputText>
                <apex:inputText style="width: 200px;" value="{!testValue}">
                   <apex:outputLabel styleClass="labelCol vfLabelColTextWrap"><!--This is from Inspect Element-->
                   Pain Points with Alternatives (Other)
                   </apex:outputLabel>&nbsp;&nbsp;&nbsp; 
                </apex:inputText>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
0

For a new record, the account acc is null. This will create problems. Initialize the variable:

    if(String.isNotBlank(accId)) {
        acc = [SELECT Id, Name, Beachhead_Attributes__c, Pain_points_with_alternative__c, Benefit_Sought__c, Estimated_Budget__c, Estimated_Campaign_Timing__c, Prospect_s_target_audience_s__c, Exposure_to_TV_Ad__c,Attendees__c, Customer_Segmentation__c, Account_Status__c, Activity_Type__c, Meeting_Type__c, Primary_Lead_Source__c, Campaign__c, Discovery_Meeting__c, Pre_Meeting_Brief__c, Due_Date__c, SM_Presentation__c FROM Account WHERE Id =: accId];
    } else {
        acc = new Account();
    }

Alternatively, I'd recommend just changing your code to use the built-in functionality of the StandardController:

acc = (Account)controllger.getRecord();

This provides automatic support for loading records from the database based on your markup. You'll need to change your variables to use the standard controller reference:

            <apex:outputField value="{!Account.Benefit_Sought__c}">

This also removes the need to hardcode the titles.

| improve this answer | |
  • i did update my main controller as per your suggestion. However, i'm still unable to save stuff or get the values back to controller. Please let me know what am i missing above. Thanks! – SMorse Mar 23 at 21:55
  • Hi @sfdcfox, i ended up adding a save method & replaced Public pagereference save() method with Public void save() & that helped me saving the record. However, i still don't understand why public pagereference save() didn't work not it wasn't able to retrieve the edited values. I might be missing something out here but if you know the reason please do share your knowledge. Thank you! – SMorse Mar 23 at 22:30
  • Hi @sfdcfox - as part of my testing i found that i cannot edit single field at a time & save. Instead I need to edit all fields and then hit save in order for the responses to be captured. Not sure why, please let me know your thoughts. Thanks! – SMorse Mar 24 at 1:31

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.