0

I have searched but i didn't get how to fix this issues Actually I'm making callout to Google Vision Api from salesforce apex class. When i m uploading image with more text content, response from Google Api will be more than 6MB and getting error in apex class. Below is the screenshot.

enter image description here

How to handle this scenario in apex?

1 Answer 1

2

It's very likely that you can't handle this in Salesforce alone. The max limit of heap that we get is 12 MB (when running code async).

Typical approaches will consume over 2x the size of the response in heap (one copy of the data is contained in the HttpResponse object, and you make another, larger copy of that same data when you deserialize). Thus, a response over 6 MB can never be deserialized in Salesforce given the current governor limits.

You could try using regular expressions to extract only certain pieces of data from the response (and this callout would need to be run async if the response is over 6 MB), but I wouldn't really recommend that.

The most realistic approach is probably to have another server, under your control, that sits between Salesforce and the Google API. You would remove unnecessary data and then pass it on to Salesforce (once the payload is at or below about 2 MB, which leaves some heap for you to use for other things after deserializing the payload).

1
  • 1
    N.B. regex can only examine up to 1MB before hitting another limits exception
    – cropredy
    Commented Sep 19, 2019 at 17:38

You must log in to answer this question.

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