• Harbir S Chahal
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
All, I am a bit stuck to complete the challenge of the Apply Service Layer Principles in Apex trail.
I have created what has been requested and tested it successfully but I keep getting the following error: 

Challenge Not yet complete... here's what's wrong: 
The Apex service does not appear to be closing cases correctly with the specified reason.

Any idea on how to debug and findout what is wrong?

Below you can see my code:

Class CaseService:

public class CaseService 
{
    public static void closeCases(Set<ID> cases, String closeReason)
    {
        System.debug('SKA - ' + cases);
        System.debug('SKA - ' + closeReason);
        List<Case> caseToUpdate = new List<Case>();
        for (Id caseId : cases)
        {
            Case c = new Case(Id = caseId);
            c.Reason = closeReason;
            c.Status = 'Closed'; 
            
            caseToUpdate.add(c);
        }
     
        update caseToUpdate;
        
    }
}

Class CaseCloseResource:

@RestResource(urlMapping='/case/*/close')
global class CaseCloseResource 
{
    @httpPost
    global static void closeCase(String closeReason)
    {
        System.debug('SKA - HTTPPOST - ' + closeReason + ' - ' + RestContext.request.requestURI);
         // Parse context
        RestRequest req = RestContext.request;
        String[] uriParts = req.requestURI.split('/');
        Id caseId = uriParts[2];
        // Call the service
        CaseService.closeCases(new Set<ID> { caseId }, closeReason);  
        
    }
}