function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
murielmuriel 

check if input check box is selected before insert

I have a visual force page which displays the current child cases linked to the selected parent case.

Each child case has a dedicated checkbox.

I need to be able to only add a comment to the selected child cases and not all child cases.

    <apex:outputText value="this is a test" rendered="false" />
    <apex:datatable value="{!related}" var="rel" width="80%">

    <apex:commandButton value="Save" action="{!save}"/>
        <apex:column headervalue="Select" width="10%">
         <apex:inputCheckbox value="{!rel.UpdateChildcases__c}"/><p/>
        </apex:column>
        <apex:column headervalue="Case Number" width="30%">
            <apex:outputLink value="/{!rel.Id}" target="_blank">{!rel.casenumber}</apex:outputLink><p/>
        </apex:column>
         <apex:column headervalue="Account Name" width="30%">
             <apex:outputLink value="/{!rel.Id}" target="_blank">{!rel.account.name}</apex:outputLink><p/>
        </apex:column>
        <apex:column headervalue="Subject" width="30%">
             <apex:outputLink value="/{!rel.Id}" target="_blank">{!rel.subject}</apex:outputLink><p/>
        </apex:column>           
       </apex:datatable>             

  <apex:commandButton value="Save"  action="{!Save}" />
</apex:form>
</apex:page>

The comment to be inserted is picked up from the text area

public with sharing class ParentCases { public List related {get; set;}

public String mysearchtext {get; set;}
public boolean selected {get; set;}

public ParentCases(ApexPages.StandardController std) {
    selected = false;  
    Case cs=(Case) std.getRecord();
    related=[select id, CaseNumber,  Subject, description, Status,UpdateChildcases__c , child_update__c, account.name from Case where parentId=:cs.id];
    }

public void Save(){

List<CaseComment> childCom = new List<CaseComment>();
for(integer i=0;i<related.size();i++){

     CaseComment newCom = new CaseComment();
newCom.CommentBody = mysearchtext;
newCom.IsPublished = TRUE;
newCom.ParentId = related[i].id;
childCom.add(newcom);
}

if(!childCom.isEmpty()){
insert childCom;

  }     

}}

this updates all child records. I really need to restrict the insert to the selected ones. ??
ShashForceShashForce
Hi,

You should use a wrapper class to implement this. Here is how you can use wrapper classes: https://developer.salesforce.com/page/Wrapper_Class

Thanks,
Shashank
murielmuriel
Thanks Shashank

Exactly what I was looking for!

Muriel