0

i'm trying to map the external system object fields with salesforce case fields.for that first i get the external object fields as JSON response after that json is deserialized and get the response as like this :

this is my wrapper class to deserialize the json response :

global class Deserialization{

        public String short_description {get;set;}  //Can't read email
        public String sys_id  {get;set;}    //9c573169c611228700193229fff72400
        public String incident_state  {get;set;}    //7
        public String urgency  {get;set;}   //1
        public String impact  {get;set;}    //1
        public String active  {get;set;}    //false


        String deserlize = '{"result":[{"short_description":"Cant read email","sys_id":"9c573169c611228700193229fff72400","incident_state":"7","urgency":"1","impact":"1","active":"false"}]}';            
        ResponseResult theresult = (ResponseResult)JSON.deserialize(deserlize,  ResponseResult.class);

        System.debug('result' + theresult);

        public class ResponseResult
        {
            public ResponseResult()
            {
                result = new List<Deserialization>();
            }

            public List<Deserialization> result;

        }


  }

this is the response i get

[result=(ResponseData:[active=false, impact=1, incident_state=7, short_description=Cant read email, sys_id=9c573169c611228700193229fff72400, urgency=1])]

here i want to map this fields with salesforce case object fields as like this

impact = priority(salesforce field)
incident_state = status(salesforce field )
short_description = subject(salesforce field )
sys_id = servicenowid(salesforce external id field)

help me to map that fields

Thanks In Advance

0

You can iterate through result and assign value to case object fields. Try this code.

String deserlize = '{"result":[{"short_description":"Cant read email","sys_id":"9c573169c611228700193229fff72400","incident_state":"7","urgency":"1","impact":"1","active":"false"}]}';            
ResponseResult theresult = (ResponseResult)JSON.deserialize(deserlize,  ResponseResult.class);
System.debug('result' + theresult);

for(Deserialization d : theresult.result){
    System.debug('impact ' + d.impact);
    System.debug('incident_state ' + d.incident_state);
    System.debug('short_description ' + d.short_description);
    System.debug('sys_id ' + d.sys_id);

    Case c = new Case();
    c.Id = **case id**
    c.priority = d.impact;
    c.Status = d.incident_state;
    c.Subject = d.short_description;
    //------add more fields if needed-------
}

Output:

10:37:22:020 USER_DEBUG [7]|DEBUG|impact>> 1
10:37:22:020 USER_DEBUG [8]|DEBUG|incident_state>> 7
10:37:22:020 USER_DEBUG [9]|DEBUG|short_description>> Cant read email
10:37:22:020 USER_DEBUG [10]|DEBUG|sys_id>> 9c573169c611228700193229fff72400

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy