1

I have below page where I can show different records under different sections based on their record type. Now I have to update only those records where User checks checkbox Confirm_Attestation_abv__c and leave rest. Can someone please guide me here?

Apex page snippet for a particular section:

  <style type="text/css">
        .controls{
        background-color:Yellow;
        font-weight:bold;
        }
    </style>
    <apex:outputText rendered=" {!Compliance_Incident_Transaction_abv__c.Outcome_abv__c} = -1"></apex:outputText>
    <apex:pageBlock title="Compliance Incident Details for {!Compliance_Incident_Transaction_abv__c.Owner.Name}" id="pb1"  >
        <apex:form >
            <apex:commandButton value="Back" action="{!cancel}" reRender=""/>
        </apex:form>
        <apex:pageMessages id="pms" />
        <apex:outputpanel id="pmem">
            <apex:PageMessage severity="Error" rendered="{!oInc.Outcome_abv__c !=null}">There are open transactions for which an outcome has not been selected.</apex:PageMessage>
        </apex:outputpanel>
        <apex:pageBlockSection id="coachingsection" title="Coaching Information" columns="1" rendered="{!oInc.Outcome_abv__c == null && Compliance_Incident_Transaction_abv__c.Confirm_Attestation_abv__c == true}">
            <apex:form >
                <apex:outputText >Coaching is already completed for this Incident.</apex:outputText>
                <br/>            
                <b>Coached By: </b>
                <apex:outputField value="{!Compliance_Incident_Transaction_abv__c.Attested_By_abv__c}" />
                <br/>
                <b>Submitted Date: </b>
                <apex:outputField value="{!Compliance_Incident_Transaction_abv__c.Attested_Datetime_abv__c}" label="Submitted Date"/>
                <br/>         
            </apex:form>
        </apex:pageBlockSection>
        <apex:pageBlockSection id="confirmSection" title="Confirm" columns="1" rendered="{!oInc.Outcome_abv__c == null && Compliance_Incident_Transaction_abv__c.Confirm_Attestation_abv__c == false}">
            <apex:form >
                <apex:outputText >By Clicking on Submit button, I acknowledge that I have monitored and completed the required assessment form for the assigned sales representative/field representative.</apex:outputText>
                <br/>

                <apex:commandButton value="Submit" action="{!confirmAttest}" reRender=""/>
            </apex:form>
        </apex:pageBlockSection>
<apex:outputPanel layout="none" rendered="{!IF(oIncTranListHCPSpeaker.size>0, true, false)}">
                <br/><br/>
                <apex:tabPanel >
                    <apex:tab label="Speaker Program Attendees" >
                        <apex:pageBlockTable id="Speaker" columns="9" value="{!oIncTranListHCPSpeaker }" border="true" var="itr3" cellPadding="4" >
                        <apex:column headerValue="Coach">
                            <apex:inputField value="{!Compliance_Incident_Transaction_abv__c.Confirm_Attestation_abv__c}"/></apex:column>

                            <apex:column headerValue="Incident ID ">
                                <apex:outputLink value="/{!itr3.Id}">{!itr3.Name}</apex:outputLink>
                            </apex:column>
                            <apex:column value="{!itr3.Account_abv__c}"/>
                            <!--  <apex:column value="{!itr3.Call_abv__c}"/>              -->
                            <apex:column value="{!itr3.Product_abv__c}"/>
                            <apex:column value="{!itr3.Time_of_Event_ABS_abv__c}"/>
                            <apex:column value="{!itr3.Audit_Reason_abv__c}"/>
                            <apex:column headerValue="Transaction Type" value="{!itr3.Recordtype.name}"/>
                            <apex:column headerValue="Outcome" >
                                <apex:actionRegion >                                    
                                    <apex:actionStatus id="SaveStatus">
                                        <apex:facet name="start"  >                                            
                                            <apex:outputText value="Saving...!" />
                                        </apex:facet>
                                        <apex:facet name="stop"  >
                                            <apex:image url="/img/msg_icons/confirm16.png" title="Saved Successfully" rendered="{!itr3.Id == targetId}" />
                                        </apex:facet>
                                    </apex:actionstatus>
                                    <apex:inputField value="{!itr3.Outcome_abv__c}" onchange="jsCallSave('{!itr3.Id}','{!itr3.Recordtype.name}');"  rendered="{!itr3.Confirm_Attestation_abv__c == false}">
                                    </apex:inputField>
                                    <apex:inputField label="Transaction Type" value="{!itr3.Recordtype.name}" style="display:none;"/>
                                </apex:actionRegion>
                                <apex:outputField value="{!itr3.Outcome_abv__c}" rendered="{!itr3.Confirm_Attestation_abv__c == true}"/>
                            </apex:column>
                        </apex:pageBlockTable>
                    </apex:tab>
                </apex:tabPanel>
            </apex:outputPanel>``

Controller snippet: // This method runs on click on Submit button

public PageReference confirmAttest() {//Called from Submit

       for(Compliance_Incident_Transaction_abv__c oInc : oIncListy)
        if (oIncListy.size() == 0) {

            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Incident is not available');

            ApexPages.addMessage(msg);

        } else { 
       for(Compliance_Incident_Transaction_abv__c o : oIncListy)
           { 

            o.Attested_Datetime_abv__c = DateTime.Now();

            o.Attested_By_abv__c = UserInfo.getUserId();

            o.Status_abv__c = 'Closed';
            o.Confirm_Attestation_abv__c =Attest;//Stamp Confirm_Attestation_abv__c 

           }

           try
           {
            update oIncListy;

}

catch( Exception x)
{    
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please try again after changing outcome');

            ApexPages.addMessage(msg);


}
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'Successfully Attested');

            ApexPages.addMessage(msg);

        }

        return null;

    }

enter image description here

2

You can do one thing create a for loop for checking that how many records in the collection have Confirm_Attestation_abv__c field is checked on, and create a new collection for that and just run update DML operation for new collection. But when you fetch these records again the value of Confirm_Attestation_abv__c field will be already set so you need to uncheck them before performing the operation again.

| improve this answer | |
  • But I am not able to reflect user entry for the checkbox in controller. Even the checkbox is checked once, the page reloads and shows it as unchecked – Testing_SFDC Jul 6 '15 at 8:51
  • You are calling a method "jsCallSave('{!itr3.Id}','{!itr3.Recordtype.name}');" on onchange of checkbox field thats why your page gets reload. – Amit Chaudhary Jul 6 '15 at 9:20
  • How Can I restrict that reload although use jsCallSave. I just want that section to reload . – Testing_SFDC Jul 6 '15 at 9:53
  • 2
    you can do one thing create a apex:actionfunction named as "jsCallSave" and you can use rerender attribute for reloading particular section by specifying component id, and by using action attribute of actionfunction you can call also JavaScript method. – Amit Chaudhary Jul 6 '15 at 10:02

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.