+ Start a Discussion

Need help on WebService Class

I am new in Integration please help me to "write an Apex class to import data from https://jsonplaceholder.typicode.com/users and store it in a created custom object" and please tell me how can I achieve this and what process should I follow to achieve the requirement.
SwethaSwetha (Salesforce Developers) 
Hi Akash,
Looks like you want to parse data from Json(https://jsonplaceholder.typicode.com/users) to apex. You can try online convertor https://json2apex.herokuapp.com/

To store data in custom object, retrieve that custom object record and use JSON.serialize() method. It will return a String containing JSON format of that record. Refer https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm#apex_class_System_Json. 

Also see https://salesforce.stackexchange.com/questions/195686/json-to-store-on-custom-object/195689 for more details



Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Hi Swetha,

I am attaching the screenshot that what I had done yet and please guide me on what to do next

Wrapper Class:
public class UserWrapper {

    public class Geo {
		public String lat;
		public String lng;

	public class Company {
		public String name;
		public String catchPhrase;
		public String bs;

	public Integer id;
	public String name;
	public String username;
	public String email;
	public Address address;
	public String phone;
	public String website;
	public Company company;

	public class Address {
		public String street;
		public String suite;
		public String city;
		public String zipcode;
		public Geo geo;

	public static List<UserWrapper> parse(String json) {
		return (List<UserWrapper>) System.JSON.deserialize(json, List<UserWrapper>.class);

Main Class:
global class DataImport {
    public static HttpResponse getMap(String Id){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = http.send(request);
        if(response.getStatusCode() == 200){
            String body = response.getBody();
            System.debug('body: '+body);
            List<UserWrapper> result = UserWrapper.parse(response.getBody());
            System.debug('result : '+result);
        return response;

SwethaSwetha (Salesforce Developers) 
HI Akash,
Looks like the screenshot is missing.Are you seeing any error message? Can you run the below URI in the REST Explorer and see if it fetches the result you want?

If this information helps, please mark the answer as best.Thank you