@RestResource(urlMapping='/*')
global class InsertAccount
{
@Httppost
global static String InsertAccount()
{
// Insert Account Using Post Method
Account acc = new Account();
String jsonStr = null;
if (null != RestContext.request.requestBody){
jsonStr = RestContext.request.requestBody.toString();
Map<String, object> m = (Map<String, object>)JSON.deserializeUntyped(jsonStr );
system.debug('******'+m );
acc.Name=(String)m.get('AccountName');
insert acc;
}
return 'Account Inserted';
}
@HttpGet
global static String InsertAccountRest()
{
// Insert Account Using Get Method
Account acc1 = new Account();
acc1.Name=RestContext.request.params.get('AccountName');
insert acc1;
return 'Account Inserted';
}
}
> For Executing the REST API Please do following steps
- Select your Environment and API Version then checked the terms of service
- Then click on Login With Salesforce
Using GetMethod
Using Post Method
Apex
,
Rest API
No comments:
Post a Comment