@RestResource(urlMapping='/Account/*') //@RestResource digunakan untuk URL Mapping yang menjadi Query URL yang digunakan dalam menembak API
global class REST_Insert_Account {
global class RESTResult {
String Status;
String Message;
String AccountId;
List<String> Errors;
RESTResult(String Status, String Message, String AccountId) {
this.Status = Status;
this.Message = Message;
this.AccountId = AccountId;
this.Errors = new List<String>();
}
}
@HttpPost
global static RESTResult doPost() {
RESTResult restResult = new RESTResult('', '','');
RestResponse res = RestContext.response;
String param = RestContext.request.requestBody.toString().trim();
Map<String, Object> paramMap = (Map<String, Object>) JSON.deserializeUntyped(param);
try {
Account newAccount = new Account();
newAccount.Name = (String) paramMap.get('Name');
insert newAccount;
restResult.Status = '0';
restResult.Message = 'Success Create Data';
restResult.AccountId = newAccount.Id;
return restResult;
} catch (Exception e) {
restResult.Status = '1';
restResult.Message = e.getMessage();
return restResult;
}
}
}