Let's say I have a generic "container" record that is used to store JSON responses from third-party API's. These Container records have a single field 'data', which is a JSON string identifying various values
I want to take this data and use Apex to parse it into an Apex map and use the data to create new records with it. And I want to do this for potentially large data sets.
for(containerRecord__c record : listOfContainerRecordsToParse) {
List<Application__c> applicationsToCreate = new List<Applications__c>();
Map<String, String> data = ...parse record JSON data field into an Apex map...
Application__c app = new Application__c (
Name = data.get('applicant_last_name') + ' - Application',
...Assign a bunch of other fields...
)
//Add new app to list
applicationsToCreate.add(app);
};
//Insert the list of records
insert applicationsToCreate;
Ok, easy enough. But now what if I want to try and associate this new record with a Contact record (using some common matching, for example, same first and last name). My initial thought was I could do a SOQL query in the for loop trying to find a matching contact...but for large numbers that would hit the governance limit, would it not?
But, because each contact will be unique, I can't think of a way of doing this that doesn't involve looping over each record and running a SOQL query inside of it to find the possible matching contact.
Has anyone done something like this? What would be the correct way to do this and not hit governance limits?