An effort to bring a revolution in Salesforce.

Wednesday, 29 July 2015

How to Insert Account Using Rest API In Salesforce ?


 
@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

 
,

No comments:

Post a Comment

Get Gmail, Docs, Drive, and Calendar for business