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
RAHUL KARMAKARRAHUL KARMAKAR 

Urgent need of the below vf page code


On Case record users should be able to put a case comment. Case is a standard object and Case Comment should be a custom object. Case detail page should be a VF Page and should display Case Comments Related List in an Expand/Collapase. I am on a urgent need of the code of the vf page please help me out
 
karthikeyan perumalkarthikeyan perumal
Hello Rahul, 

kindly use the Code below and override the standard View Option in case. the code works for you well and customize the code according to your fitment. 

also i found the duplicate Question for the same.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000g2SVIAY

VF page Code: 
<apex:page standardController="Case" showHeader="true" sidebar="true" extensions="CaseEditExtension" >
    <apex:form id="myForm">
        <apex:sectionHeader title="Case Edit" subtitle="{!Case.CaseNumber}"/>
        <apex:pageBlock id="pgBlock" mode="edit" title="Case Edit">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!Save}" />
                <apex:commandButton value="Save & Close" action="{!SaveAndClose}" />
                <apex:commandButton value="Save & New" action="{!SaveAndNew}" />
                <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="pgBlockSectionAcctInfo" title="Case Information" collapsible="false" columns="2" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Case Owner</apex:outputLabel>                   
                    <apex:outputField id="caseOwner" value="{!case.ownerid}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Status</apex:outputLabel>
                    <apex:inputField id="caseStatus" value="{!case.Status}" />
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Case Number</apex:outputLabel>                   
                    <apex:inputField id="caseNumber" value="{!case.CaseNumber}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Priority</apex:outputLabel>
                    <apex:inputField id="casePriority" value="{!case.Priority}" />
                </apex:pageBlockSectionItem>               
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Contact Name</apex:outputLabel>                   
                    <apex:inputField id="caseContact" value="{!case.ContactId}" />
                </apex:pageBlockSectionItem>               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Case Origin</apex:outputLabel>
                    <apex:inputField id="caseOrigin" value="{!case.Origin}" />
                </apex:pageBlockSectionItem>  
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Account Name</apex:outputLabel>                   
                    <apex:inputField id="caseAccount" value="{!case.AccountId}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Type</apex:outputLabel>                   
                    <apex:inputField id="caseType" value="{!case.Type}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Case Reason</apex:outputLabel>                   
                    <apex:inputField id="caseReason" value="{!case.Reason}" />
                </apex:pageBlockSectionItem>      
            </apex:pageBlockSection>
           
            <apex:pageBlockSection id="pgBlockSectionAdditionalInfo" title="Additional Information" collapsible="false" columns="2">
            </apex:pageBlockSection>
           
            <apex:pageBlockSection id="pgBlockSectionDescriptionInfo" title="Description Info" collapsible="false" columns="2">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Subject</apex:outputLabel>                   
                    <apex:inputText id="caseSubject" value="{!case.Subject}" size="75" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Description</apex:outputLabel>                   
                    <apex:inputTextArea id="caseDescription" value="{!case.Description}" cols="75" rows="6" />
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Internal Comments</apex:outputLabel>                   
                    <apex:inputTextArea id="caseInternalComments" value="{!Comment}" cols="75" rows="6" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
            </apex:pageBlockSection>
           
            <apex:pageBlockSection id="pgBlockSectionOptional" title="Optional" collapsible="false" columns="1">
                <apex:inputCheckBox value="{!UseAssignmentRules}" label="Assign using active assignment rules" />
            </apex:pageBlockSection>           
        </apex:pageBlock>     
       
        <apex:pageBlock > 
        <apex:pageBlockTable value="{!case.casecomments}" var="c"> 
         
        <apex:column value="{!c.IsPublished }" headerValue="Public" /> 
        <apex:column value="{!c.commentbody}" headerValue="Comment"/>
        <apex:column value="{!c.CreatedById }" headerValue="Created By"/> 
        <apex:column value="{!c.LastModifiedById}" headerValue="Last Modified By"/>  
        </apex:pageBlockTable> 
        </apex:pageBlock> 
              
    </apex:form>
     
</apex:page>

Class page Code: 
 
public with sharing class CaseEditExtension {
    public String Comment
    {
        get;
        set;
    }
    public String Description
    {
        get;
        set;
    } 
    public String Subject
    {
        get;
        set;
    }
    public Boolean UseAssignmentRules
    {
        get;set;
    }
   
    public Case cs;
    ApexPages.StandardController controller;
   
    public CaseEditExtension(ApexPages.StandardController con)
    {
        controller = con;
        this.cs = (Case) con.getRecord();
    }
   
    public PageReference Save()
    {
        CaseComment com = new CaseComment();
        if(Comment.Length() > 0)
        {
            com.commentBody = Comment;
            com.ParentId = cs.Id;
            if(UseAssignmentRules == true)
            {
                AssignmentRule  AR = new AssignmentRule();
                AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
               
                //Creating the DMLOptions for "Assign using active assignment rules" checkbox
                Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
                controller.getRecord().setOptions(dmlOpts);               
            }
            insert com;
        }
        String retURL = ApexPages.currentPage().getParameters().get('retURL');
        String CurrentId = ApexPages.currentPage().getParameters().get('id');
        PageReference redirectPG;
        if(retURL != null)
            redirectPG = new PageReference('/' + retURL);
        else if(CurrentId != null)
            redirectPG = new PageReference('/' + CurrentId);
       
        controller.Save();
       
        return redirectPG;
    }
   
    public PageReference SaveAndNew()
    {
        Save();
        return new PageReference('/500/e');
    }
   
    public PageReference SaveAndClose()
    {
        Save();
        String retURL = ApexPages.currentPage().getParameters().get('retURL');
        String CurrentId = ApexPages.currentPage().getParameters().get('id');
        PageReference redirectPG;
        if(retURL != null)
            redirectPG = new PageReference('/' + retURL);
        else if(CurrentId != null)
            redirectPG = new PageReference('/' + CurrentId);
       
        return redirectPG;
    }   
}

Hope it will help you. mark best ANSWER if its work for you.

Thanks
Karthik

 
Ravi_SFDCRavi_SFDC

Hi Karthikeyan

I would need your help on the below request.

On the Account Record i do have some Account Plans for the client. For each Account Plan i do have Revenue Projections, Account Priorities, Top Opportunities etc. What is needed is I do have Custom Button (Sort Top Account Priorities)  for the Account Priorities, if i click on the  Sort Top Account Priorities custom button it should give me the top 5 Account Priorities based on the id and i should be able to change the priority and save. Your help is really appreciated.

karthikeyan perumalkarthikeyan perumal
Hello Venkata, 

i think you are posted original issue in this link..
https://developer.salesforce.com/forums/?id=906F0000000g2fAIAQ
i will use this link for further update.. 
Thanks
Karthik 
Ravi_SFDCRavi_SFDC
Thank you Karthik.