I have a task to query a million records from one org and then upsert them in another org. I use a Bulk API query job to get all records.
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:OrgIntegration/services/data/v58.0/jobs/query/id/results?locator=MTAwMDA&maxRecords=1000000');
request.setMethod('GET');
request.setHeader('Accept', 'text/csv');
request.setHeader('Accept-Encoding', 'gzip');
Http http = new Http();
HttpResponse response = http.send(request);
But I have the error: "Apex heap size is too large". I need that CSV to pass it to another Bulk API job - to insert records (also in Apex). So can you please give me any ideas for how I can deal with that large response?