I am hitting SOQL Limits when I update a record from my custom object "OnBoarding_Data__c" . I have a trigger that is designed to create multiple "Case" records on before update. And as soon as the Case is created, I write the Id back to the main object - so it doesn't run again.
I look at the logs and it has many SOQL queries that are not part of my logic - but in "Case". It looks like other Flow / Process Builder / Trigger logic that executes SOQL when a Case record is created. See, creating 1 Case is not a problem, but creating 4 or 5 hits the limit.
I am wondering if there's another way of achieving this without worrying about the limits for creating Cases. Is using REST API an option? Would REST act as a separate execution thread for each case being built? I'm reading up on Async Apex - does anyone have experience with that?
Here is a sample of my code for reference:
trigger OnBoardingTrigger on OnBoarding_Data__c (before update) {
for(OnBoarding_Data__c onbd : Trigger.new){
if(onbd.Case1 != null){
OnBoardingCase obc = new OnBoardingCase(onbd);
obc.createCase1(onbd);
}
/*****I have multiple of these if statements******/
}
}
Inside the class method: (I have multiple of these methods that do the almost the same thing)
public void createCase1(OnBoarding_Data__c onb) {
Case cs = new Case();
cs.Name = 'test'
insert cs;
onb.Case1__c = cs.Id
}
Any advice would be greatly appreciated.