Skip to main content
HI there,

Below my code was working fine, but suddenly pass an error, when I try to attach a document,

Custom API for Case Attachment,

@RestResource(urlMapping='/CaseAttachment/*')

global with sharing class CaseAttachment{

@HttpGet

    global static List<Attachment> getCaseById() {

       RestRequest req = RestContext.request;

        RestResponse res = RestContext.response;

        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          List<Attachment> result =  [Select id, Name, OwnerId, BodyLength, LastModifiedById, LastModifiedDate, ContentType, Body, Description, CreatedDate, CreatedById from Attachment where ParentId = :Id];

        return result;

        }

           

@HttpPost

  global static void doget(String type, String body, String ContentType, String ParentID){

        RestRequest req = RestContext.request;

        RestResponse res = RestContext.response;

        if(Test.isRunningTest()){

        String CaseName=req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        //String doc=EncodingUtil.Base64Encode(req.requestBody);

        }

        

         Attachment a = new Attachment();

            a.Name = type;

            a.Body = Blob.valueOf(body);           

            a.ContentType = ContentType;

            a.ParentId = ParentID;

                

        insert a;

        

        

    }

}

Below the resultUnexpected parameter encountered during deserialization for case attachmentCan someone help with this asap.
2 个回答
  1. 2019年2月19日 15:12
    Try this  .. Please update the correct parent Id

     

    {

    "type": "test",

    "body": "test",

    "ContentType": "text",

    "ParentID": "500..........W"

    }

     
0/9000