14

I just tried to insert a bunch of external object records (external data source being a postgre on Heroku). Noticed it took significant amount of time. After looking at the debug logs I realised that the new methods Database.InsertAsync() and Database.InsertImmediate() are not bulkified. I ran the following code in the developer console:

List <ExternalObject__x> records = new List <ExternalObject__x> ();

for (Integer i = 0; i < 48; i++)
{
    records.add(new ExternalObject__x(Name__c = 'TestBB ' + i));
}

Database.insertImmediate(records);

The debug log output is:

15:36:21.3 (6698016)|DML_BEGIN|[8]|Op:Insert|Type:ExternalObject__x|Rows:48
15:36:21.27 (27334305)|CALLOUT_REQUEST|System.HttpRequest[Endpoint=https://odata-us.heroku.com/odata/v4/randomHash/heroku$externalObject, Method=POST]
15:36:21.989 (989710929)|CALLOUT_RESPONSE|System.HttpResponse[Status=Created, StatusCode=201]
15:36:21.990 (990543138)|CALLOUT_REQUEST|System.HttpRequest[Endpoint=https://odata-us.heroku.com/odata/v4/randomHash/heroku$externalObject, Method=POST]
15:36:22.761 (1761926976)|CALLOUT_RESPONSE|System.HttpResponse[Status=Created, StatusCode=201]
15:36:22.762 (1762741796)|CALLOUT_REQUEST|System.HttpRequest[Endpoint=https://odata-us.heroku.com/odata/v4/randomHash/heroku$externalObject, Method=POST]
15:36:23.184 (2184963373)|CALLOUT_RESPONSE|System.HttpResponse[Status=Created, StatusCode=201]
15:36:23.185 (2185860982)|CALLOUT_REQUEST|System.HttpRequest[Endpoint=https://odata-us.heroku.com/odata/v4/randomHash/heroku$externalObject, Method=POST]
15:36:23.633 (2633244019)|CALLOUT_RESPONSE|System.HttpResponse[Status=Created, StatusCode=201]
15:36:23.634 (2634095011)|CALLOUT_REQUEST|System.HttpRequest[Endpoint=https://odata-us.heroku.com/odata/v4/randomHash/heroku$externalObject, Method=POST]
15:36:24.57 (3057260889)|CALLOUT_RESPONSE|System.HttpResponse[Status=Created, StatusCode=201]
// more of these instances... and then finally
15:36:42.903 (21903634108)|DML_END|[8]

Which shows that SFDC performed a callout to the oData provider for each of the records in my collection.

Inserting 48 records took ~21 seconds.

Is there anything config-wise or even salesforce-support-wise that can be done to bulkify this thing or is this a normal bad behaviour?

In case it's the only way to go, I'd love to know the reason why this can't be done in one go.

1 Answer 1

4

Response from SFDC Support Tier 3:

As per the current design this behavior is not bulkified. But you can probably raise an idea for the same.

Regarding the long run times, it is some thing dependent on the processing times of the record insert on the external and the response received from the external server.

That's a shame...

2
  • Very much awful. Did you end up writing your own bulkified REST calls in Apex?
    – Mossi2
    Jul 27, 2017 at 22:39
  • Yep, we wrote a webservice as a workaround Jul 28, 2017 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .