JSON Parsing with Apex in Salesforce – Part III

by Sudipta Deb | Oct 17, 2014 | Apex, JSON, learn salesforce | 0 comments

Hello friends,

In this post, I am going to share the information how to parse multiple JSON request and display the same in Visual Force page in tabular format.

If you haven’t visited my previous posts regarding JSON parsing, please go to below links –
JSON Parsing with Apex in Salesforce – Part I
JSON Parsing with Apex in Salesforce – Part II

So let’s start.
First the Visual Force Page-

<apex:page controller="CountryController">
<apex:form >
<apex:pageBlock Title="JSON Parser Example - Multiple Data">
<apex:commandButton value="Parse Multiple JSON Data" action="{!parseJSONData}"
reRender="countryData" />
</apex:pageBlock>
<br />
<apex:pageBlock id="countryData">
<apex:pageBlockTable value="{!countries}" var="country">
<apex:column headerValue="Country Name" value="{!country.countryName}"/>
<apex:column headerValue="Country Capital" value="{!country.countryCapital}"/>
<apex:column headerValue="Country Currency" value="{!country.countryCurrency}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Now the controller-

public class CountryController {
private List<CountryDataWrapper> countryDataWrapper;

public void parseJSONData(){
countryDataWrapper = new ParseMultipleJsonData().parse();
}

public List<CountryDataWrapper> getCountries(){
return countryDataWrapper;
}
}

The wrapper class to hold Country information-

public class CountryDataWrapper {
public String countryName{get;set;}
public String countryCapital{get;set;}
public String countryCurrency{get;set;}
}

And finally the parser class doing the parsing

public class ParseMultipleJsonData {
public List<CountryDataWrapper> parse() {
String jsonMessage = '[{'+
' "countryName": "India",'+
' "countryCapital": "Delhi",'+
' "countryCurrency": "Indian rupee"'+
'},'+
'{'+
' "countryName": "Switzerland",'+
' "countryCapital": "Bern",'+
' "countryCurrency": "Swiss franc"'+
'},'+
'{'+
' "countryName": "United States of America",'+
' "countryCapital": "Washington, D.C.",'+
' "countryCurrency": "US Dollar"'+
'}]';

return (List<CountryDataWrapper>) System.JSON.deserialize(jsonMessage, List<CountryDataWrapper>.class);
}
}

That’s all. Let’s see how the Visual force page is behaving now-
Initially the page looks like –

Now when we clicked on the “Parse Multiple JSON Data” button, it parsed the JSON data and displayed in tabular format like below-

If you have any feedback, please share with me. Thanks in advance.

Written by

Related Posts

New Apex Method | Extracting Picklist Values Based on Record Type Inside Apex

New Apex Method | Extracting Picklist Values Based on Record Type Inside Apex

For years, Salesforce developers have faced a common challenge: programmatically retrieving picklist values that are specific to a certain Record Type directly within Apex. The “solutions” often involved either complex SOQL queries against metadata, relying on the UI API (with its associated callout limits and serialization overhead), or maintaining clunky custom metadata/settings.

Good news, Technical Potpourri readers! The Salesforce Spring ’26 release is bringing a game-changer that will significantly simplify your Apex code and improve performance: native Apex methods to filter picklist values by Record Type!

read more...
Apex Cursor and Its Advantages Over Batch Processing

Apex Cursor and Its Advantages Over Batch Processing

Struggling with large datasets and SOQL governor limits in Salesforce? In this video, I will dive deep into Apex Cursors, the powerful new feature that revolutionizes how we process millions of records.

Apex Cursors allow developers to navigate through query results in manageable chunks within a single transaction or across Queueable jobs. In this video, I will show you the correct way to implement Apex Cursor and also when this is an exception, how to handle that and perform retry.

read more...
Perform Inline Edit And Sort Inside Flow Data Table

Perform Inline Edit And Sort Inside Flow Data Table

I’ll show you exactly how to use the new data table component features from Salesforce’s Spring 26 release. Learn how to implement inline editing and column sorting directly within your screenflow, making your workflow automation more efficient. This update offers significant enhancements for any salesforce developer working with flowbuilder.

Also I have shown how to save the inline edit changes properly in the salesforce.

read more...

0 Comments

Leave a Reply