+ Start a Discussion
igressigress 

Bulk API and Custom Apex Rest End point

I have a custom rest end point that I created using Apex Class. I call this rest end point from my app every time a new account is created. If 100 accounts are created I make 100 API calls. 
I want to use Bulk API so that I can avoid individual calls every time an account is created. I need to use my MyRestEndPoint because it has some business logic inside it which does extra processing apart from upserting the account.

@RestResource(urlMapping='/MyRestEndPoint')
global with sharing class MyRestEndPointClass {
    @HttpPost
    global static String doPost(Account account){            
        //Custom code - 

        return 'something'
    }   
}

Any help is much appreciated

Thanks
Best Answer chosen by igress
pconpcon
You should be able to make your parameter to your post be List<Account> accounts and then have your payload be something like
 
{
    "accounts": [
        {
            "id": "xxxxxx",
            "name": "account1"
        },
        {
            "id": "xxxxxx",
            "name": "account2"
        },
        {
            "id": "xxxxxx",
            "name": "account3"
        },
        {
            "id": "xxxxxx",
            "name": "account4"
        }
    ]
}

This will allow you to interact with multiple records with a single REST call.