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
ManojKumar MuthuManojKumar Muthu 

Apex code to view list of comments (Custom object) related to case

Hi All,

I created a custom object Name "Casecomments" related to Case object and below the Apex code I use to view all "Casecomments" created to a particular case by passing case id,

@RestResource(urlMapping='/CaseComments__c/*')
global with sharing class CaseComments__cListview{

@HttpGet
    global static List<CaseComments__c> getCaseComments__cId() {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
          List<CaseComments__c> result =  [Select id from CaseComments__c where Case__c=:id];
        return result;
    }

I am facing this error,
Error: Compile Error: Invalid character in identifier: CaseComments__cListview at line 2 column 27

can someone help me on this. 
thanks in advance.
 
Best Answer chosen by ManojKumar Muthu
PawanKumarPawanKumar
Please try below.

@RestResource(urlMapping='/CaseComments__c/*')
global with sharing class CaseCommentscListview{

@HttpGet
    global static List<CaseComments__c> getCaseCommentsId() {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
          List<CaseComments__c> result =  [Select id from CaseComments__c where Case__c=:id];
        return result;
    }


 

All Answers

PawanKumarPawanKumar
Please try below.

@RestResource(urlMapping='/CaseComments__c/*')
global with sharing class CaseCommentscListview{

@HttpGet
    global static List<CaseComments__c> getCaseCommentsId() {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
          List<CaseComments__c> result =  [Select id from CaseComments__c where Case__c=:id];
        return result;
    }


 
This was selected as the best answer
ManojKumar MuthuManojKumar Muthu
Seriously!.... I owe you a beer man.  Thanks a ton.