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
Trevor ViallTrevor Viall 

Create multiple post records

I am trying to create a post that can take in more than one record at a time. I am hitting a bit of a brick wall and was hoping someone could help me with an answer. how would I allow this to take in multiple employee records together.

    public static HttpResponse PostEmployeeCallout(){
        http http = new http ();
        HttpRequest request = new HttpRequest();
        //Set the Endpoint of the Post callout
        request.setEndpoint('https://sfdnewhires.herokuapp.com/api/v3/employees');
        //Set the method to be a post callout
        request.setMethod('POST');
        //declairing the header type and the format of the response
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        list <object> employees = (List<Object>) results.get('employees');
        request.setBody(body);
        HttpResponse response = http.send(request);       
    }
    public class body{
        String Name {get;set;}
        String hire_Date {get;set;}
        String position {get;set;}
        String email {get;set;}
        Integer phone {get;set;}
        String functional_area {get;set;}
        String Location {get;set;}
        String type {get;set;}
    }
    public body(String Name, String hire_Date, String position, String email, Integer phone, String functional_area, String Location, String type){
        this.name = name;
        this.hire_date = hire_Date;
        this.position = position;
        this.email = email;
        this.phone = phone;
        this.functional_area = functional_area;
        this. location = Location;
        this.type = type;
    }
}

 
Abhishek BansalAbhishek Bansal
Hi Trevor,

You should convert the list of sObjects in to JSON and than pass it to the body. Use the below method:
JSON.serialize(employees);
Now pass this JSON string in body.

Let me know if you need any further help on ths.

Thanks,
Abhishek Bansal.
Kallu KaliaKallu Kalia
While looking for the best sound systems you need to consider many things such as sound quality, weight, size, and price. Some like Creative 2.1 speakers in India while others prefer a minimum price system