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
HayaHaya 

havinga problem getting a field from Cases

I am trying to collect fields from the Case database, some for display and one for editing.

 

The fields for display are: CaseNumber, Accountid, Subject, Description, Contactid, Ownerid, CreatedDate 

 

The field I want to update is: Comment.

 

I would like to display prior Comments and give the user the option to add a Comment.

 

I am successful in collecting the first set of fields but when I add Comment to the list I get:

                                                                     

Error: Compile Error: No   such column 'Comment' on entity 'Case'. If you are attempting to use a custom   field, be sure to append the '__c' after the custom field name. Please   reference your WSDL or the describe call for the appropriate names. at line   14 column 12

 

I see Comment ilisted n the Case Standard Fields

 

How do I collect the field?

 

Here is my code:

public class RequestViewExtension {
    public Case cs;
        ApexPages.StandardController controller;
   
    public RequestViewExtension (ApexPages.StandardController con)
    {
        controller = con;
        this.cs = (Case) con.getRecord();
    }

    public list<Case> case1{get;set;}
    public list<Case> getcases()
    {
     case1=[Select Priority,CaseNumber,Accountid,Subject,Description,Contactid,Ownerid,CreatedDate from case where CaseNumber=:ApexPages.currentPage().getParameters().get('CaseNumber')];  
     return case1;
    }
    
    public String Comment
    {
        get;
        set;
    }
}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Try to use as per follow

 

Take one object instace in your apex class and use it in your VF page.

 

Visualforce page:

<apex:outputField value="{!objCaseComment.CommentBody}"/> 

 Apex Class:

public CaseComment objCaseComment{get; set;}

 

Thank You,
Hitesh Patel
SFDC Certified Developer & Admini

 

All Answers

hitesh90hitesh90

Hi,

 

CaseComment is another Salesforce standard object. it is child object of case.

 

To get and update caseComment you have to write innser SOQL query on casecomment object.

 

Example:

case1=[Select Priority,CaseNumber,(select CommentBody from CaseComments),Accountid,Subject,Description,Contactid,Ownerid,CreatedDate from case where CaseNumber=:ApexPages.currentPage().getParameters().get('CaseNumber')];  

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

HayaHaya

Thank you Hitesh Patel,

 

I think that worked, I was able to save with no errors.

 

Now how do I display it in the vf page?

 

<div style="clear:both;width:500px; height: 50px;">
<p style="font-size:1.2em; text-align:right; color:#1fbdf2; float:left; width: 30%;">Comment:</p>
<p style="font-size:1.2em; text-align:left;color:black; float:left; margin-left: 15px; width: 50%;"> <apex:outputField value="{!s.CommentBody}"/> </p>
<div style="clear:both;">
</div>

</div>

 

I get the error:

Error: Could not resolve field 'CommentBody' from <apex:outputField> value binding '{!s.CommentBody}' in page Viewed_Request

 

I tried  !CaseComments.CommentBody and got the same error.

 

 

 

 

hitesh90hitesh90

Try to use as per follow

 

Take one object instace in your apex class and use it in your VF page.

 

Visualforce page:

<apex:outputField value="{!objCaseComment.CommentBody}"/> 

 Apex Class:

public CaseComment objCaseComment{get; set;}

 

Thank You,
Hitesh Patel
SFDC Certified Developer & Admini

 

This was selected as the best answer
HayaHaya

It worked.

Thank you so much :)