You need to sign in to do that
Don't have an account?
Laxmi jeevan
How to Parse the Data by using Map into different objects
String response=httpResp .getBody();
System.debug('*** response is '+response);
Map<String,object> deserializedMap = (Map<String,object>)JSON.deserializeUntyped(response);
System.debug('deserializedMap value is::::'+deserializedMap);
Map<string,Object> responseObj = (Map<string,Object>)deserializedMap.get('response');
Hi Here I'm able to getting Response(total key& Value)& I spilted into Key, Based on Key how to get the vaues in List .
System.debug('*** response is '+response);
Map<String,object> deserializedMap = (Map<String,object>)JSON.deserializeUntyped(response);
System.debug('deserializedMap value is::::'+deserializedMap);
Map<string,Object> responseObj = (Map<string,Object>)deserializedMap.get('response');
Hi Here I'm able to getting Response(total key& Value)& I spilted into Key, Based on Key how to get the vaues in List .
If this code does not help you, please provide the JSON data you are getting back (or at least an example of it) and I can help you.
NOTE: Please use the "Add a code sample" button (icon <>) when adding code to increase readability and make it easier to reference.
All Answers
If this code does not help you, please provide the JSON data you are getting back (or at least an example of it) and I can help you.
NOTE: Please use the "Add a code sample" button (icon <>) when adding code to increase readability and make it easier to reference.
Thank you your reply, I will send my json data.Actually my requirement is i insert json data in salesforce in different objects,here opportunity is parent object and some child objectsdata coming from external system.can you give briefly eplanation.
{
"OpportunitySearch":[
{
"Services":[
],
"Competitors":[
],
"Alumni":[
],
"PursuitTeamMembers":[
{
"IsDeleted":null,
"BusinessEntityID":2890510,
"PursuitTeamID":2890510,
"PersonnelNbr":"00338306",
"OpportunityNumber":null,
"ClientName":null,
"Name":"Hofstee, Kevin (US - Los Angeles)",
"Email":"khofstee@deloitte.com",
"PursuitTeamRoleCode":"Z0000085",
"PursuitTeamRoleDesc":"Pursuit Leader",
"IsReadOnly":false,
"IsDirty":false,
"CreatedByApplication":null,
"ModifiedByApplication":null
},
{
"IsDeleted":null,
"BusinessEntityID":2890511,
"PursuitTeamID":2890511,
"PersonnelNbr":"00338306",
"OpportunityNumber":null,
"ClientName":null,
"Name":"Hofstee, Kevin (US - Los Angeles)",
"Email":"khofstee@deloitte.com",
"PursuitTeamRoleCode":"Z0000135",
"PursuitTeamRoleDesc":"Entered By",
"IsReadOnly":false,
"IsDirty":false,
"CreatedByApplication":null,
"ModifiedByApplication":null
},
{
"IsDeleted":null,
"BusinessEntityID":2890512,
"PursuitTeamID":2890512,
"PersonnelNbr":"00125680",
"OpportunityNumber":null,
"ClientName":null,
"Name":"Bonner-Witt, Katrina (US - Miami)",
"Email":null,
"PursuitTeamRoleCode":"Z0000139",
"PursuitTeamRoleDesc":"FSS Lead - Consulting",
"IsReadOnly":true,
"IsDirty":false,
"CreatedByApplication":null,
"ModifiedByApplication":null
},
{
"IsDeleted":null,
"BusinessEntityID":2890513,
"PursuitTeamID":2890513,
"PersonnelNbr":"00338306",
"OpportunityNumber":null,
"ClientName":null,
"Name":"Hofstee, Kevin (US - Los Angeles)",
"Email":"khofstee@deloitte.com",
"PursuitTeamRoleCode":"Z0000139",
"PursuitTeamRoleDesc":"FSS Lead - Consulting",
"IsReadOnly":true,
"IsDirty":false,
"CreatedByApplication":null,
"ModifiedByApplication":null
},
{
"IsDeleted":null,
"BusinessEntityID":2890514,
"PursuitTeamID":2890514,
"PersonnelNbr":"00364032",
"OpportunityNumber":null,
"ClientName":null,
"Name":"Stillings, Suzanne (US - Houston)",
"Email":null,
"PursuitTeamRoleCode":"Z0000139",
"PursuitTeamRoleDesc":"FSS Lead - Consulting",
"IsReadOnly":true,
"IsDirty":false,
"CreatedByApplication":null,
"ModifiedByApplication":null
}
],
"IsReproposal":null,
"IsRecurringOpportunity":null,
"IsSMBDInvlolved":null,
"IsConfidential":false,
"IsLinkedOpportunity":false,
"IsPullThroughOpportunity":null,
"IsDeloitteSolutionCenter":null,
"IsThereRFP":false,
"IsNewOpportunity":true,
"PursuitStartDate":"2015-07-22T00:00:00",
"ExpectedPursuitCloseDate":"2017-01-01T00:00:00",
"ProjectStartDate":null,
"ProjectEndDate":null,
"OppActualCloseDate":null,
"RFPReleaseDate":null,
"RiskAssessmentComplianceStatus":null,
"RiskAssessmentScore":null,
"RiskAssessmentDate":null,
"RiskConsultationDate":null,
"RiskReviewDate":null,
"UserAlias":null,
"DelegateAlias":null,
"LastModifiedOn":"2015-10-28T18:01:37.61",
"InitiativeCode":188,
"SICCode":0,
"LawFirmCode":null,
"PrivateEquityCode":null,
"InhouseCounselCode":null,
"TypeOfRecurringWork":null,
"DSCId":null,
"PullThroughOriginalOppID":null,
"OriginalOpportunityID":0,
"ConsultingFunctionCount":3,
"Client":null,
"ModifiedOnRTrak":null,
"CreatedOnRTrak":"2015-07-22T17:43:58.85",
"ModifiedByRTrak":"Hofstee, Kevin (US - Los Angeles)",
"CreatedByRTrak":"Hofstee, Kevin (US - Los Angeles)",
"Region":null,
"FiscalYear":null,
"IntegratedMarketOfferingCodeID":null,
"IntegratedMarketOfferingCodeDesc":null,
"PhaseReasonDescription":null,
"_modifiedByApplication":null,
"BusinessEntityID":10346444,
"OpportunityID":10346444,
"OpportunityName":"Dev: Test Siemens Opportunity 2",
"OpportunityDescription":"",
"CanUserViewThisOpportunity":0,
"ClientID":"0001014861",
"ClientName":"SIEMENS CORPORATION",
"CanUserViewClient":0,
"ParentClientID":"8000008106",
"ParentClientName":"SIEMENS CORPORATION",
"CanUserViewParentClient":0,
"LCSPName":"Pleasance, David (US - Atlanta)",
"LCSPEmail":"dpleasance@DELOITTE.com",
"PursuitLeaderID":"00338306",
"PursuitLeaderName":"Hofstee, Kevin (US - Los Angeles)",
"PursuitLeaderEmail":"khofstee@deloitte.com",
"AttestFlag":false,
"DPSClientGroup":null,
"ConsultingSectorOfferingCodeID":"0010",
"ConsultingSectorOfferingCodeDesc":"Not Applicable",
"LawFirmDescription":null,
"PrivateEquityDescription":null,
"InhouseCounselDescription":null,
"TotalValue":8000000.00,
"TotalPotentialNetServiceRevenue":0.00,
"GrossRevenue":null,
"FeeTypeCode":null,
"FeeTypeDescription":null,
"PhaseCode":"Z03",
"PhaseDescription":"Qualified",
"PhaseReasonCode":null,
"ProbabilityOfSuccess":10,
"InitiativeDescription":"ADV-COMP SYS VDATE",
"PriorityCode":"4",
"PriorityDescription":"Low",
"IntegratedServiceOfferingCode":"NA",
"IntegratedServiceOfferingDescription":" NA",
"VBBCaseCode":null,
"VBBCaseDescription":null,
"Optional1":null,
"Optional2":null,
"Optional3":null,
"Optional4":null,
"Optional5":null,
"PhaseRank":40,
"IsDirty":true,
"OriginalOpportunityName":null,
"CanViewEditOriginalOpportunity":0,
"QualityReviewValue":"0",
"QualityReviewComment":"",
"QualityReviewerName":null,
"AreThereCompetitors":0,
"AreThereAlumni":0,
"TypeOfRecurringWorkDesc":null,
"PullThroughOriginalOppName":null,
"CanViewEditPullThroughOriginalOpportunity":0,
"BuyerName":null,
"BuyerRoleCode":null,
"BuyerRoleDescription":null,
"EngagementIndustry":null,
"DSCName":null,
"ReasonCodeDesc":null,
"CreatedByApplication":null,
"ModifiedByApplication":null
}
]
}
Then deserialize into that object
You could also do some really convoluted typecasting to get all the way down into what you need to get to.
What i did i send to you.can you give the reply
This is my class can you modify any changes.
public with sharing class OppsearchTestingCtrl {
//Variables Declaration
public List<OpportunitySearch > oppList{ get; set;}
public OppsearchTestingCtrl (){ }
public PageReference submit() {
Http http = new Http();
HttpRequest httpReq= new HttpRequest();
HttpResponse httpResp = new HttpResponse();
httpReq.setMethod('POST');
httpReq.setEndpoint('https://test.testing.com/api/Opportunity/Search');
String authorizationHeader = 'BASIC testencrptformat=';
system.debug('authorizationHeader is '+authorizationHeader );
httpReq.setHeader('Authorization',authorizationHeader );
httpReq.setHeader('Content-Length', '0');
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setTimeout(120000);
//beliw String is single Record
String requestBody='{"UserAlias": "test","Modifiedon_RTRAKFrom": "2015-10-28T10:40:00.0805308-10:00","Modifiedon_RTRAKTo": "2015-10-28T11:40:00.0805309-11:00"}';
httpReq.setBody(requestBody);
httpResp = http.send(httpReq);
String response=httpResp .getBody();
Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(response);
List<Object> lstCustomers = (List<Object>)results.get('OpportunitySearch');
Object[] aryCustomers = (Object[]) results.get('OpportunitySearch');
for (Object Opptycustomer : lstCustomers) {
Map<String, Object> customerAttributes = (Map<String, Object>)Opptycustomer;
for (String attributeName : customerAttributes.keyset()) {
}
}
return null;
}
public class PursuitTeamMembers {
public Object IsDeleted;
public Integer BusinessEntityID;
public Integer PursuitTeamID;
public String PersonnelNbr;
public Object OpportunityNumber;
public Object ClientName;
public String Name;
public String Email;
public String PursuitTeamRoleCode;
public String PursuitTeamRoleDesc;
public Boolean IsReadOnly;
public Boolean IsDirty;
public Object CreatedByApplication;
public Object ModifiedByApplication;
}
public class Services {
}
public List<OpportunitySearch> OpportunitySearch;
public class OpportunitySearch {
public List<Services> Services;
public List<Services> Competitors;
public List<Services> Alumni;
public List<PursuitTeamMembers> PursuitTeamMembers;
public Object IsReproposal;
public Object IsRecurringOpportunity;
public Object IsSMBDInvlolved;
public Boolean IsConfidential;
public Boolean IsLinkedOpportunity;
public Object IsPullThroughOpportunity;
public Object IsDeloitteSolutionCenter;
public Boolean IsThereRFP;
public Boolean IsNewOpportunity;
public String PursuitStartDate;
public String ExpectedPursuitCloseDate;
public Object ProjectStartDate;
public Object ProjectEndDate;
public Object OppActualCloseDate;
public Object RFPReleaseDate;
public Object RiskAssessmentComplianceStatus;
public Object RiskAssessmentScore;
public Object RiskAssessmentDate;
public Object RiskConsultationDate;
public Object RiskReviewDate;
public Object UserAlias;
public Object DelegateAlias;
public String LastModifiedOn;
public Integer InitiativeCode;
public Integer SICCode;
public Object LawFirmCode;
public Object PrivateEquityCode;
public Object InhouseCounselCode;
public Object TypeOfRecurringWork;
public Object DSCId;
public Object PullThroughOriginalOppID;
public Integer OriginalOpportunityID;
public Integer ConsultingFunctionCount;
public Object Client;
public Object ModifiedOnRTrak;
public String CreatedOnRTrak;
public String ModifiedByRTrak;
public String CreatedByRTrak;
public Object Region;
public Object FiscalYear;
public Object IntegratedMarketOfferingCodeID;
public Object IntegratedMarketOfferingCodeDesc;
public Object PhaseReasonDescription;
public Object modifiedByApplication;
public Integer BusinessEntityID;
public Integer OpportunityID;
public String OpportunityName;
public String OpportunityDescription;
public Integer CanUserViewThisOpportunity;
public String ClientID;
public String ClientName;
public Integer CanUserViewClient;
public String ParentClientID;
public String ParentClientName;
public Integer CanUserViewParentClient;
public String LCSPName;
public String LCSPEmail;
public String PursuitLeaderID;
public String PursuitLeaderName;
public String PursuitLeaderEmail;
public Boolean AttestFlag;
public Object DPSClientGroup;
public String ConsultingSectorOfferingCodeID;
public String ConsultingSectorOfferingCodeDesc;
public Object LawFirmDescription;
public Object PrivateEquityDescription;
public Object InhouseCounselDescription;
public Double TotalValue;
public Double TotalPotentialNetServiceRevenue;
public Object GrossRevenue;
public Object FeeTypeCode;
public Object FeeTypeDescription;
public String PhaseCode;
public String PhaseDescription;
public Object PhaseReasonCode;
public Integer ProbabilityOfSuccess;
public String InitiativeDescription;
public String PriorityCode;
public String PriorityDescription;
public String IntegratedServiceOfferingCode;
public String IntegratedServiceOfferingDescription;
public Object VBBCaseCode;
public Object VBBCaseDescription;
public Object Optional1;
public Object Optional2;
public Object Optional3;
public Object Optional4;
public Object Optional5;
public Integer PhaseRank;
public Boolean IsDirty;
public Object OriginalOpportunityName;
public Integer CanViewEditOriginalOpportunity;
public String QualityReviewValue;
public String QualityReviewComment;
public String QualityReviewerName;
public Integer AreThereCompetitors;
public Integer AreThereAlumni;
public String TypeOfRecurringWorkDesc;
public String PullThroughOriginalOppName;
public Integer CanViewEditPullThroughOriginalOpportunity;
public String BuyerName;
public String BuyerRoleCode;
public String BuyerRoleDescription;
public String EngagementIndustry;
public String DSCName;
public String ReasonCodeDesc;
public String CreatedByApplication;
//public String ModifiedByApplication;
}
public static OppsearchTestingCtrl parse(String json) {
return (OppsearchTestingCtrl ) System.JSON.deserialize(json, OppsearchTestingCtrl.class);
}
}
to
Thank you your reply.
whenn i put below line in my code, i am getting error
OpportunitySearch oppSearch = JSON.deserialize(response, OpportunitySearch.class);
MY Error:
Error: OppsearchTestingCtrl Compile Error: Initial term of field expression must be a concrete SObject: List<OppsearchTestingCtrl.OpportunitySearch>
I changed single to List this one also i am getting error.i called below line.
List<OpportunitySearch > oppList = (List<OpportunitySearch >) JSON.deserialize(response, List<OpportunitySearch >.class);
My Error:
Visualforce ErrorHelp for this Page
System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set
Error is in expression '{!submit}' in component <apex:commandButton> in page oppsearchtesting: (System Code)
Class.OppsearchTestingCtrl.submit: line 54, column 1
line no 54 means : List<OpportunitySearch > oppList = (List<OpportunitySearch >) JSON.deserialize(response, List<OpportunitySearch >.class);
then via the developer console run the following
After you confirm that the debug prints out "Dev: Test Siemens Opportunity 2" then you can update the submit method to do the authorization you need to do.