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, 2022 in SalesForce by surbhi
• 3,820 points
3,563 views

1 answer to this question.

0 votes

Because some fields in Apex Salesforce are reserved terms, it can't be done with a simple "JSON.deserialize" function. What is the severity of the wrapper ban? 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 ;)

Hope this helps!

Check out the salesforce admin training today to learn more!

answered Mar 2, 2022 by surbhi
• 3,820 points

Related Questions In SalesForce

+1 vote
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, 2022 in SalesForce by CoolCoder
• 4,420 points

edited Jun 27, 2023 by Khan Sarfaraz 9,665 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, 2022 in SalesForce by surbhi
• 3,820 points
1,223 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, 2022 in SalesForce by CoolCoder
• 4,420 points
3,354 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, 2022 in SalesForce by CoolCoder
• 4,420 points

edited Jun 19, 2023 by Khan Sarfaraz 7,540 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
3,403 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,030 points
1,045 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,030 points
759 views
0 votes
2 answers

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

Hi @Vardhan, I took Edureka's Salesforce Online Training, ...READ MORE

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

edited Dec 22, 2021 by Soumya 729 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, 2022 in SalesForce by surbhi
• 3,820 points
4,061 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, 2022 in SalesForce by surbhi
• 3,820 points
2,886 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP