function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AKASH DEEPAKASH DEEP 

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

https://salesforce.stackexchange.com/questions/51856/insert-new-records-in-to-custom-object-from-json-string-in-salesforce

https://www.biswajeetsamal.com/blog/json-response-parsing-in-salesforce-apex/#

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
 
AKASH DEEPAKASH DEEP
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:
@RestResource(urlMapping='/ExternalUser/*')
global class DataImport {
    
    public static HttpResponse getMap(String Id){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://jsonplaceholder.typicode.com/users');
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        
        if(response.getStatusCode() == 200){
            System.debug(response.getBody());
            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?
/services/apexrest/ExternalUser/3

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