Json response to be deserialized in Apex salesforce lightning

0 votes

0

I am getting the below Json Response by hitting a RestAPI.

**

[
    {
        "index": 0,
        "object": {
            "attributes": {
                "ID": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/ID",
                        "ov": true,
                        "value": "5",
                        "uri": "entities/attributes/ID/2Cqf5xG2"
                    },
                    {
                        "type": "configuration/entityTypes/Customer/attributes/ID",
                        "ov": true,
                        "value": "3028",
                        "uri": "entities/attributes/ID/fto38ZRR"
                    }
                ],
                "IgpId": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpId",
                        "ov": true,
                        "value": "1911",
                        "uri": "entities/attributes/IgpId/20ft8omYM"
                    }
                ],
                "IgpName": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpName",
                        "ov": true,
                        "value": "Dr. heath",
                        "uri": "entities/attributes/IgpName/20ft8oe1q"
                    }
                ],
                "IgpID": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpID",
                        "ov": true,
                        "value": "1872",
                        "uri": "entities/attributes/IgpID/20ft8oiI6"
                    }
                ],
                "IgpNAME": [
                    {
                        "type": "configuration/entityTypes/Customer/attributes/IgpNAME",
                        "ov": true,
                        "value": "Dr Jc crook",
                        "uri": "entities/attributes/IgpNAME/20ft8oqoc"
                    }
                ]
            }
        },
        "successful": true
    }
]

**

I am trying to save the values for CoachID (3028), IgpID(1872), IgpId(1911), IgpName(Dr. heath), IgpNAME(Dr Jc crook) in String variables in APex class.

I have used a map to do so but unable to get the proper values. I wanted to get the above values in a List & return that list from function.

Can anyone help me on this? I am not supposed to do this using wrapper.

Mar 2 in SalesForce by surbhi
• 3,810 points
276 views

1 answer to this question.

0 votes
Because some fields in Apex are reserved terms, it can't be done with a simple "JSON.deserialize" function. What is the severity of the wrapper ban? I wouldn't type this stuff by hand, but you can go to https://json2apex.herokuapp.com/, check the box for explicit parser (which would happen anyway because you have reserved terms), and presto, you have a ready class and a cool stab at a unit test / demonstration of how to use the code. It's been tried and true; if you can't utilise it, your project has greater issues ;)
answered Mar 2 by surbhi
• 3,810 points

Related Questions In SalesForce

0 votes
1 answer

Apex (Salesforce) read json from response and store it in a string variable

String jsonStr = '{ "oktaToken":"eyJraWQiOiIyNlN1NHFMNnVVZTVJX2M5X2Z3WmZvX09ON0dNUHRtQzlEeHFsTGplLS00IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlVINmdIOF9BcWJ" }'; Map<String, String> ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
1,038 views
0 votes
0 answers

Apex (Salesforce) read json from response and store it in a string variable

I am trying to hit a API ...READ MORE

Mar 4 in SalesForce by surbhi
• 3,810 points
149 views
0 votes
1 answer

How to Update RecordTypeId field in Lightning record form in salesforce?

A critical action that messes everything up ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
518 views
0 votes
1 answer

How to add days to date time in Salesforce Apex?

Beware the DST issue! The "addDays" function ...READ MORE

answered Mar 15 in SalesForce by CoolCoder
• 4,360 points
521 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
1,873 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,010 points
302 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,010 points
182 views
0 votes
1 answer

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 216 views
0 votes
1 answer

Salesforce Apex/JSON serialization with change on variable name

Apex does not support annotation for serialization. But, ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
301 views
0 votes
1 answer

Salesforce Test Class - System.NullPointerException: Attempt to de-reference a null object

Because testAccount.account is never set, it is ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
279 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP