You need to sign in to do that
Don't have an account?
sfdc dev 2264
Case trigger bulkification help needed
Hi,
I have a trigger which is updating account id on case object , The logic is working fine, I just want to bulkify the trigger with the best coding standards as i have written a query inside a for loop
Kindly help me with that pls
Thanks in Advance
I have a trigger which is updating account id on case object , The logic is working fine, I just want to bulkify the trigger with the best coding standards as i have written a query inside a for loop
Kindly help me with that pls
MY TRIGGER : trigger trgAccountAutopopulate on Case (before insert,before update) { if(Trigger.isbefore){ Id groupwaiversRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Group Waivers').getRecordTypeId(); for(Case casenew: Trigger.new){ if(casenew.Recordtypeid==groupwaiversRecordTypeId ){ if(casenew.IATA_DAI__c!=null){ Account AccIATA=[Select id, IATA_Number__c from account where IATA_Number__c =: casenew.IATA_DAI__c limit 1]; casenew.Accountid=AccIATA.id; } if(casenew.TIDS__c!=null){ Account AccTIDS=[Select id, Agency_TIDS_Number__c from account where Agency_TIDS_Number__c =: casenew.TIDS__c limit 1]; casenew.Accountid=AccTIDS.id; } } } } }
Thanks in Advance
Here is what I can offer you though...
see the below trigger,
If you have less than 50,000 Accounts who has IATA_Number__c or Agency_TIDS_Number__c as not null then trigger is good to go for now.
But if you think you may have way of than 50,000 accounts with either IATA_Number__c != null or Agency_TIDS_Number__c != null then I would say you need to implement the batch apex.
Again, let's say you have 200,000 Accounts in your org and let's say there are 150,000 of them has Agency_TIDS_Number__c and IATA_Number__c both blank then you don't need to worry about batch apex. But however, that is very less likely to be the scenario.
Hope this helps!
I modified the code through a map
Pls let me know the modified code is fine or need any modifications,
Let us know if this will help you