You need to sign in to do that
Don't have an account?
raz r
I want to Parse the below JSON and results should be displayed in VF Page as Accounts with related contacts.
I want to Parse the below JSON and results should be displayed in VF Page as Accounts with related contacts.
JSON:
{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v39.0/sobjects/Account/00190000016V11FAAS"},"Id":"00190000016V11FAAS","Name":"birlasoft","Contacts":{"totalSize":6,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYh46AAD"},"Id":"0039000002MYh46AAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgxfAAD"},"Id":"0039000002MYgxfAAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgXrAAL"},"Id":"0039000002MYgXrAAL","Name":"Riaz Test"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhF4AAL"},"Id":"0039000002MYhF4AAL","Name":"Deepika HR"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhHoAAL"},"Id":"0039000002MYhHoAAL","Name":"Romit Shilpe"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000001AlZ2XAAV"},"Id":"0039000001AlZ2XAAV","Name":"Riazgood boy"}]}}]}
Thanks in Advance!
JSON:
{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v39.0/sobjects/Account/00190000016V11FAAS"},"Id":"00190000016V11FAAS","Name":"birlasoft","Contacts":{"totalSize":6,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYh46AAD"},"Id":"0039000002MYh46AAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgxfAAD"},"Id":"0039000002MYgxfAAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgXrAAL"},"Id":"0039000002MYgXrAAL","Name":"Riaz Test"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhF4AAL"},"Id":"0039000002MYhF4AAL","Name":"Deepika HR"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhHoAAL"},"Id":"0039000002MYhHoAAL","Name":"Romit Shilpe"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000001AlZ2XAAV"},"Id":"0039000001AlZ2XAAV","Name":"Riazgood boy"}]}}]}
Thanks in Advance!
WRAPPER CLASS
now deserialize your JSON like this, place json string in a variable called jsnstrring
Am receiving below error.
Missing dependent object: Class: Riazdev.JSONwrapper.cls_records
Please asist.
DEBUG|response{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v39.0/sobjects/Account/00190000016V11FAAS"},"Id":"00190000016V11FAAS","Name":"birlasoft","Contacts":{"totalSize":6,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYh46AAD"},"Id":"0039000002MYh46AAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgxfAAD"},"Id":"0039000002MYgxfAAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgXrAAL"},"Id":"0039000002MYgXrAAL","Name":"Riaz Test"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhF4AAL"},"Id":"0039000002MYhF4AAL","Name":"Deepika HR"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhHoAAL"},"Id":"0039000002MYhHoAAL","Name":"Romit Shilpe"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000001AlZ2XAAV"},"Id":"0039000001AlZ2XAAV","Name":"Riazgood boy"}]}}]}
Please assist.
DEBUG|wrapperJsonwrapper:[done=true, records=(Account:{Id=00190000016V11FAAS, Name=birlasoft}), totalSize=1]
Please assist.
Apex Type unsupported in JSON: Object
Error is in expression '{!getresposnsefromCallout}' in component <apex:commandButton> in page accountswithrelatedcontactsdisplay: Class.System.JSON.deserialize: line 15, column 1
Class.Riazdev.AccountswithReplatedContacts.getresposnsefromCallout: line 26, column 1
LINE NO:26 : wrapper= (JSONwrapper) System.JSON.deserialize(response, JSONwrapper.class);
Illegal value for primitive
Error is in expression '{!getresposnsefromCallout}' in component <apex:commandButton> in page accountswithrelatedcontactsdisplay: Class.System.JSON.deserialize: line 15, column 1
Class.Riazdev.AccountswithReplatedContacts.getresposnsefromCallout: line 26, column 1
https://salesforce.stackexchange.com/questions/107506/convert-sobjects-containing-child-parent-records-into-a-map
and sub class is
DEBUG|wrapperJsonwrapper:[done=true, records=(RecordVO:[children=null, recordFields=null]), totalSize=1]
below link will help you to display accounts and contacts in your pageblock table
https://developer.salesforce.com/forums/?id=906F0000000AxfCIAS
I am calling this ParentChildJSON class in another class.but I ddin't get the acclist and conlist into the main class. How to get those lists into Main class.
The below is my main class:
public class AccountswithReplatedContacts {
public list<Account>acc{get;set;}
public String Accountname{get;set;}
public String Response {get;set;}
public ParentChildJSON pcJson{get;set;}
public AccountswithReplatedContacts(){
//getresposnsefromCallout();
}
public void getresposnsefromCallout(){
//String search=''+Accountname+'';
// system.debug('searchstring'+search);
String Endpoint='https://'+URL.getSalesforceBaseUrl().getHost()+'/services/data/v39.0/query/?q=SELECT +Id,Name,(select +id,Firstname,Lastname +From+Contacts) +FROM + Account + where + name=\''+String.escapeSingleQuotes(Accountname)+'\'';
System.debug('Endpoint'+Endpoint);
HttpRequest req = new HttpRequest();
req.setMethod('GET');
string autho = 'Bearer '+userInfo.getSessionId();
req.setHeader('Authorization', autho);
req.setEndpoint(Endpoint);
Http http = new Http();
HTTPresponse res= http.send(req);
response = res.getBody();
system.debug('response'+response);
ParentChildJSON.readJSON(response);
}
}
Here , the getresposnsefromCallout method is caling from button in VF page.
Could you please assist.
Thanks!!
inside readJSON initialize them.
you can access them like
When I tried to declare as above am getting error like
variable doesnot exist ParentChildJSON.acclist;
variable doesnot exist ParentChildJSON.contlist;
Please assist.
https://www.freelancer.in/u/chbalayesu89