Since a standard Salesforce related list cannot be customized beyond the available configuration options, you need to create a custom Visualforce-based related list and embed it in the Page Layout to add custom functionality such as inline editing or custom actions. This article provides a working code example that creates a custom Visualforce-based related list for Case Comments, embedded in a Case page layout, that allows users to toggle the isPublished field value inline and save changes without a page redirect.
The standard "save" functionality cannot be used since it redirects the page after the save. The solution below can be embedded into a Case Page Layout and allows users to modify the isPublished value of Case Comments inline.
Sample Code : Visual force page:
<!-- This is a Custom VisualForce page that will display the CaseComments related list.
It also has input field for the user to change the value of isPublished on CaseComments.
Embed this page into a Case Page Layout -->
<apex:page standardcontroller="case" extensions="checkbox" tabstyle="case">
<apex:pageBlock title="Case Comments" mode="new" >
<apex:form >
<apex:commandButton value="Save" action="{!customSave}"/>
<!-- This is the Custom Save Button -->
<apex:pageBlockTable value="{!Records}" var="index">
<!-- The pageBlockTable iterates through the list of the custom Class -->
<apex:column > <apex:inputCheckbox value="{!index.published}"/> </apex:column> <!-- Stores the input value from the user -->
<apex:column value="{!index.comment.isPublished}"/>
<!--Display the CaseComments information -->
<apex:column value="{!index.comment.CommentBody}"/>
</apex:pageblocktable>
</apex:form>
</apex:pageBlock>
</apex:page>
Sample Code : Apex Class
public class checkbox {
public class AssignComment
// This class will be used to store the corresponding input from the user and the CaseComment.
{
public CaseComment comment {get; set;} //This will store the CaseComment.
public Boolean published {get; set;} //This will store the input from the user.
public AssignComment(){} //Empty constructor.
}
public List<assignComment> Records {get; set;}
//This will store the list of CaseComments as well as the corresponding user inputs.
public checkbox(ApexPages.StandardController controller)
{
Records = new List<AssignComment>();
Case Record = (Case) controller.getRecord();
//Get case from controller.
for (CaseComment Node : [Select commentBody, isPublished from CaseComment where parentId = :Record.Id])
//Query and loop through all the CaseComments.
{
assignComment temp = new AssignComment();
// Create temp to insert into the list Records.
temp.comment = Node;
temp.published = Node.isPublished;
Records.add(Temp);
}
}
public PageReference CustomSave()
//This class will take the input from the user and update the corresponding CaseComments.
{
List<CaseComment> updateList = new List<CaseComment>();
//Create a list of CaseComments to be updated.
for (AssignComment a : Records) //Loop through Records.
{
a.comment.isPublished = a.published;
//Update CaseComments with user input.
updateList.add(a.comment);
}
update(updateList);
return null;
}
}
This code is a sample implementation for the Case Comment related list. Before deploying to production: replace the isPublished field references with your actual target field API names; replace the CaseComment object references with the target related object; add error handling for DML exceptions (try/catch with ApexPages.addMessage); consider adding CRUD/FLS checks before querying and updating; test with your org's specific page layout and profile assignments.
000384992

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.