I'm creating a REST endpoint in Salesforce in order to import a big set of contacts (2 million) and apply some custom logic to the insert (which I don't want in a trigger because it's a one-time thing).
So, the issue I'm concerned with is that heap size might be surpassed. Obviously, we're not going to send the 2 million contacts in the same JSON, we will chunk them down in batches of 200 so the endpoint can process them comfortably, but I would still like to add some validation.
I would like to basically be able to check the JSON's size before starting the deserialization, so if it's too big, I can return a relevant response warning the user, or simply denying the batch.
Is this possible? I've checked out the JSONParser
class, but I haven't seen anything that might be of use, so that would leave me to the JSON.deserializeUntyped(jsonString)
option.
Any help is appreciated.