• awaken88
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Hey Guys,

 

I'm currently trying to go through all my code and make everyhing much more efficient..

 

Which means I'm trying to reduce the number of calls through statements etc.

 

I'm struggling to get my head around the MAP Class..

 

What I'm trying to do is Map All Accounts, but within my trigger I need to be able to call upon the specific account which matches Key__c from a custom object and return all account details.

 

I'm currently doing that with a query, but unsure how I can query a MAP to return results?

 

Any help always appreciated!


Regards,

 

Richard Hubbard

Hey Guys,

 

Long time reader first time poster!

 

Zero Java experience and just currently trying to learn how to parse JSON from an API.

 

All the API call etc is fine, but it seems the more complex my JSON is the harder this is for me to wrap my head around.

 

I've managed to get a basic understanding and to get my current code to work with 2 API calls, but once I request a lot of details at once, there are multiple arrays and objects within that are causing me issue.

 

I've been using JSON2APEX which has helped a heap, but unsure if it is handling this complex request as its just not being logical in my head.

 

I've spent hours looking online and trying to understand before posting here..so any help would be greatly appreciated.

 

I'm currently able to get all the details to show and deserialize but I'm not sure then how to exactly split them into objects, for some reason only some work and not the other ones.

 

Code Below:

 

  Public static void GetComments (String Key, String I) {
                
    JSONParser parser = JSON.createParser(I);
    while (parser.nextToken() != null)
    {
      if (parser.getCurrentToken() == JSONToken.START_ARRAY)
      {
        while (parser.nextToken() != null) 
        {
          if (parser.getCurrentToken() == JSONToken.START_OBJECT) 
          {
            GetComments.Issues j; GetComments.comment l;
            try {
                j = (GetComments.Issues)parser.readValueAs(GetComments.Issues.Class);

            String s = JSON.serialize(j);
            System.Debug('Serialized Projects: ' + s);
            parser.skipChildren();
          }
        }
      }
    }    
  }

 j then becomes: 

 

05:52:29.212 (4212341000)|USER_DEBUG|[220]|DEBUG|Serialized Projects: {"self":"url","key":"pkey-84","id":"2109","fields":{"comment":{"total":2,"startAt":0,"maxResults":2,"comments":[{"updated":"2013-10-22T11:55:44.415+1000","updateAuthor":{"self":"url","name":".com.au","emailAddress":"1.com.au","displayName":"name","active":true},"self":"url","id":"24119","created":"2013-10-22T11:55:44.415+1000","body":"body of comment","author":{"self":"url","name":".com.au","emailAddress":"email@address","displayName":"dpname,"active":true}},{"updated":"2013-10-22T12:49:43.029+1000","updateAuthor":{"self":"username","name":"usrname","emailAddress":"emailaddress","displayName":"sdfsdf","active":true},"self":"url","id":"24131","created":"2013-10-22T12:49:43.029+1000","body":"notes","author":{"self":"url","name":"Test Name","emailAddress":"email@address","displayName":"name","active":true}}]}},"expand":"editmeta,renderedFields,transitions,changelog,operations","comment":null}

 

Have removed any sensitive infromation but all data there is correct.

 

But when I have it as GetComments j = (GetComments)parser.readValueAs(GetComments.Class); it returns

 

05:33:08.391 (4391422000)|USER_DEBUG|[222]|DEBUG|Serialized Projects: {"total":null,"startAt":null,"maxResults":null,"issues":null,"expand":"editmeta,renderedFields,transitions,changelog,operations"}

 

 

Which I'm happy with the first out come, it has everything that I want there.. but I have no idea how to split it down into the required fields/lists.

 

So goes Issue Array - Fields - Comment - Comments Array Author 

 

Class Below:

 

//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class GetComments {

    public class Issues {
        public String expand;
        public String id;
        public String self;
        public String key;
        public Fields fields;
        public comment comment;
    }

    public class Comments {
        public String self;
        public String id;
        public Author author;
        public String body;
        public Author updateAuthor;
        public String created;
        public String updated;
    }

    public class Fields {
        public Comment comment;
    }

    public String expand;
    public Integer startAt;
    public Integer maxResults;
    public Integer total;
    public List<Issues> issues;

    public class Comment {
        public Integer startAt;
        public Integer maxResults;
        public Integer total;
        public List<Comments> comments;
    }

    public class Author {
        public String self;
        public String name;
        public String emailAddress;
        public String displayName;
        public Boolean active;
    }

    public class Comments_Z {
    }


    public class Comment_Z {
        public Integer startAt;
        public Integer maxResults;
        public Integer total;
        public List<Comments_Z> comments;
    }

    public class Fields_Z {
        public Comment_Z comment;
    }

    
    public static GetComments parse(String json) {
        return (GetComments) System.JSON.deserialize(json, GetComments.class);
    }
  }

 

Thanks guys, any help would be appreciated..

 

Regards,

 

Richard

 

Hey Guys,

 

I'm currently trying to go through all my code and make everyhing much more efficient..

 

Which means I'm trying to reduce the number of calls through statements etc.

 

I'm struggling to get my head around the MAP Class..

 

What I'm trying to do is Map All Accounts, but within my trigger I need to be able to call upon the specific account which matches Key__c from a custom object and return all account details.

 

I'm currently doing that with a query, but unsure how I can query a MAP to return results?

 

Any help always appreciated!


Regards,

 

Richard Hubbard

Hey Guys,

 

Long time reader first time poster!

 

Zero Java experience and just currently trying to learn how to parse JSON from an API.

 

All the API call etc is fine, but it seems the more complex my JSON is the harder this is for me to wrap my head around.

 

I've managed to get a basic understanding and to get my current code to work with 2 API calls, but once I request a lot of details at once, there are multiple arrays and objects within that are causing me issue.

 

I've been using JSON2APEX which has helped a heap, but unsure if it is handling this complex request as its just not being logical in my head.

 

I've spent hours looking online and trying to understand before posting here..so any help would be greatly appreciated.

 

I'm currently able to get all the details to show and deserialize but I'm not sure then how to exactly split them into objects, for some reason only some work and not the other ones.

 

Code Below:

 

  Public static void GetComments (String Key, String I) {
                
    JSONParser parser = JSON.createParser(I);
    while (parser.nextToken() != null)
    {
      if (parser.getCurrentToken() == JSONToken.START_ARRAY)
      {
        while (parser.nextToken() != null) 
        {
          if (parser.getCurrentToken() == JSONToken.START_OBJECT) 
          {
            GetComments.Issues j; GetComments.comment l;
            try {
                j = (GetComments.Issues)parser.readValueAs(GetComments.Issues.Class);

            String s = JSON.serialize(j);
            System.Debug('Serialized Projects: ' + s);
            parser.skipChildren();
          }
        }
      }
    }    
  }

 j then becomes: 

 

05:52:29.212 (4212341000)|USER_DEBUG|[220]|DEBUG|Serialized Projects: {"self":"url","key":"pkey-84","id":"2109","fields":{"comment":{"total":2,"startAt":0,"maxResults":2,"comments":[{"updated":"2013-10-22T11:55:44.415+1000","updateAuthor":{"self":"url","name":".com.au","emailAddress":"1.com.au","displayName":"name","active":true},"self":"url","id":"24119","created":"2013-10-22T11:55:44.415+1000","body":"body of comment","author":{"self":"url","name":".com.au","emailAddress":"email@address","displayName":"dpname,"active":true}},{"updated":"2013-10-22T12:49:43.029+1000","updateAuthor":{"self":"username","name":"usrname","emailAddress":"emailaddress","displayName":"sdfsdf","active":true},"self":"url","id":"24131","created":"2013-10-22T12:49:43.029+1000","body":"notes","author":{"self":"url","name":"Test Name","emailAddress":"email@address","displayName":"name","active":true}}]}},"expand":"editmeta,renderedFields,transitions,changelog,operations","comment":null}

 

Have removed any sensitive infromation but all data there is correct.

 

But when I have it as GetComments j = (GetComments)parser.readValueAs(GetComments.Class); it returns

 

05:33:08.391 (4391422000)|USER_DEBUG|[222]|DEBUG|Serialized Projects: {"total":null,"startAt":null,"maxResults":null,"issues":null,"expand":"editmeta,renderedFields,transitions,changelog,operations"}

 

 

Which I'm happy with the first out come, it has everything that I want there.. but I have no idea how to split it down into the required fields/lists.

 

So goes Issue Array - Fields - Comment - Comments Array Author 

 

Class Below:

 

//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class GetComments {

    public class Issues {
        public String expand;
        public String id;
        public String self;
        public String key;
        public Fields fields;
        public comment comment;
    }

    public class Comments {
        public String self;
        public String id;
        public Author author;
        public String body;
        public Author updateAuthor;
        public String created;
        public String updated;
    }

    public class Fields {
        public Comment comment;
    }

    public String expand;
    public Integer startAt;
    public Integer maxResults;
    public Integer total;
    public List<Issues> issues;

    public class Comment {
        public Integer startAt;
        public Integer maxResults;
        public Integer total;
        public List<Comments> comments;
    }

    public class Author {
        public String self;
        public String name;
        public String emailAddress;
        public String displayName;
        public Boolean active;
    }

    public class Comments_Z {
    }


    public class Comment_Z {
        public Integer startAt;
        public Integer maxResults;
        public Integer total;
        public List<Comments_Z> comments;
    }

    public class Fields_Z {
        public Comment_Z comment;
    }

    
    public static GetComments parse(String json) {
        return (GetComments) System.JSON.deserialize(json, GetComments.class);
    }
  }

 

Thanks guys, any help would be appreciated..

 

Regards,

 

Richard