1

I have a list that contains a collection of wrapper class instances called tacList. The wrapper class effectively contains a checkbox which relates to a case field and a string. The string is not related to a case field but instead is intended to hold a comment for updating the case field which will later be posted to chatter. For some reason, the string value is not coming back into the apex class when I debug the response.

The wrapper fields: fieldPath, fieldLabel, fieldValue and field value all return the expected values. TaskComment is either null or blank.

Can anyone help? ...Thanks

public with sharing class GDPR_Dynamic_Extension {

    public Case thisCase {get; set;}
    public List <TaskAndComment> tacList {get; set;}
    public List <Integer> indexList = new List<Integer>();

    //Get the fields from FieldSet
    Schema.SObjectType SObjectTypeObj = Schema.getGlobalDescribe().get('Case');
    transient Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
    transient Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get('GDPR_Task_Fields');

    public Integer fieldSetSize = fieldSetObj.getFields().size();

    public List<Integer> getIntegers() {
            indexList = createIndex(fieldSetSize);
            return indexList;
    }

    public GDPR_Dynamic_Extension(ApexPages.StandardController controller) {
        controller.addFields(new String[]{
                'GDPR_IS_Apps__c',
                'GDPR_TON_Head__c'
        });
        thisCase            = (Case)controller.getRecord();
        tacList             = new List<taskAndComment>();
    }

    public List<taskAndComment> getTheList() {

        if (tacList.isEmpty()) {
            for (Schema.FieldSetMember eachFieldSetMember : fieldSetObj.getFields()) {

                String path      = eachFieldSetMember.getFieldPath();
                String label     = eachFieldSetMember.getLabel();
                Boolean value    = (Boolean)thisCase.get(eachFieldSetMember.getFieldPath());

                taskAndComment t = new taskAndComment(path, label, value);
                tacList.add(t);
            }
            return tacList;
        } else return tacList;
    }

    public PageReference processSelected() {

        for (Integer i = 0; i < tacList.size() ; i++) {
            thisCase.put(tacList[i].fieldPath, tacList[i].fieldValue);
            System.debug(tacList[i].taskComment);
        }
        update thisCase;
        return null;
    }

    public class TaskAndComment{

        public String   fieldPath   {get; set;}
        public String   fieldLabel  {get; set;}
        public Boolean  fieldValue  {get; set;}
        public String   taskComment {get; set;}

        public TaskAndComment(String theFieldPath, String theFieldLabel, Boolean theFieldValue){
            System.debug('5');
            fieldPath   = theFieldPath;
            fieldLabel  = theFieldLabel;
            fieldValue  = theFieldValue;
            taskComment = '';
        }
    }

    public static List<Integer> createIndex(Integer count){
        List<Integer> indexList = new List<Integer>();
        for (Integer i = 0; i < count; i++) {
            indexList.add(i);
        }
        return indexList;
    }

    public void postToChatter(Id c, String message){
        ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), c, ConnectApi.FeedElementType.FeedItem, message);
    }
}

..VF page:

<apex:page id="GDPR_Dynamic" StandardController="Case" extensions="GDPR_Dynamic_Extension">
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockButtons >
            <apex:commandButton value="Update Selected" action="{!processSelected}" />
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Incomplete Tasks" columns="3">
            <apex:pageBlockTable value="{!Integers}" var="i" id="theRepeat">
                <apex:column>
                    <apex:facet name="header">Name</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:outputText value="{!TheList[i].fieldLabel}"       rendered="{!IF(!TheList[i].fieldValue=true,true,false)}"/>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">Task</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:inputCheckbox value="{!TheList[i].fieldValue}"    rendered="{!IF(!TheList[i].fieldValue=true,true,false)}"/>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">Comment</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:inputText value="{!TheList[i].taskComment}"       rendered="{!IF(!TheList[i].fieldValue=true,true,false)}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Complete Tasks" columns="3">
            <apex:pageBlockTable value="{!Integers}" var="i" id="theRepeat">
                <apex:column>
                    <apex:facet name="header">Name</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:outputText value="{!TheList[i].fieldLabel}"       rendered="{!IF(!TheList[i].fieldValue=false,true,false)}"/>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">Task</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:inputCheckbox value="{!TheList[i].fieldValue}"    disabled="true" rendered="{!IF(!TheList[i].fieldValue=false,true,false)}"/>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">Comment</apex:facet>
                    <apex:facet name="footer"></apex:facet>
                    <apex:inputText value="{!TheList[i].taskComment}"       disabled="true" rendered="{!IF(!TheList[i].fieldValue=false,true,false)}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

  • Can we see the associated VF page code that's calling this class? – Brian Miller Jul 16 '18 at 13:02
1

Your calling your getTheList() method everytime in your apex:input tags, and therefore any changes you make are not calling the tacList variable's setter.

I would suggest using the list variable itself in your VF code (i.e. replace all your TheList[i] with tacList[i]) and put all the initialization code from getTheList() into your constructor OR lazy initialize in the getter of the variable itself:

public List <TaskAndComment> tacList {
    get {
        if (tacList == null) {
            tacList = new List<TaskAndComment>();
            // the rest of the initialization code
        }
        return tacList;
    }
    set;
}
  • Brian thanks so much for your input. I tried both of your ideas but unfortunately neither worked. I ended up rebuilding both the page and the extension from scratch and realised that the problem was caused by the "render=IF!TheList... " in the VF page. Once I removed these the comments came striaght through. Presumably they were moving the values to the output text in the second table or something. Anyway your effort and time was much appreciated. All the best – Jay Jul 17 '18 at 12:54
  • Happy to help and happy to hear it worked out in the end! – Brian Miller Jul 17 '18 at 14:49
0

Issue solved by removing

rendered="{!IF(!TheList[i].fieldValue=true,true,false)}"/>

from the VF page and instead passing in two lists from the controller.

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.