Notes
Request Class
public class CustomerRequest {
public string firstName;
public string lastName;
public string email;
public string phone;
public string gender;
public string status;
}
Apex Class
public class CustomerAPI {
public static void PostCustomerFromRequest(){
CustomerRequest customer = new CustomerRequest();
customer.firstName ='William';
customer.lastName = 'Wilson';
customer.email ='willim45@gmail.com';
customer.gender='Male';
customer.phone='4567654567';
customer.status='active';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.pathtosalesforce.com/customer.php?token='+token);
request.setMethod('POST');
request.setBody(JSON.serialize(customer));
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
HttpResponse response = http.send(request);
System.debug(response.getStatusCode());
System.debug(response.getStatus());
System.debug(response.getBody());
}
public static void PostCustomersFromRequest(){
List<CustomerRequest> customerList = new List<CustomerRequest>();
CustomerRequest customer1 = new CustomerRequest();
customer1.firstName ='Ava';
customer1.lastName = 'Davis';
customer1.email ='ava67@gmail.com';
customer1.gender='Male';
customer1.phone='4567654567';
customer1.status='active';
CustomerRequest customer2 = new CustomerRequest();
customer2.firstName ='Harper';
customer2.lastName = 'White';
customer2.email ='harper76@gmail.com';
customer2.gender='Male';
customer2.phone='4567654567';
customer2.status='active';
customerList.add(customer1);
customerList.add(customer2);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.pathtosalesforce.com/customer.php?token='+token);
request.setMethod('POST');
request.setBody(JSON.serialize(customerList));
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
HttpResponse response = http.send(request);
System.debug(response.getStatusCode());
System.debug(response.getStatus());
System.debug(response.getBody());
}
}