You need to sign in to do that
Don't have an account?

Need help with bulkifying trigger and deploying into prod
Hi there,
I'm using the following code to trigger a lookup to a custom object on the account. I'm currently hitting SOQL limits on this and I think its because I have a DML statement inside the loop.
Also, when I try to deploy this trigger into prod using this class, I get a coverage error saying that there is no coverage at all even though I have 100% coverage in sandox.
I'm fairly new to coding and would greatly appreicate any help you could provide!
I'm using the following code to trigger a lookup to a custom object on the account. I'm currently hitting SOQL limits on this and I think its because I have a DML statement inside the loop.
trigger AccountTerritoryTag on Account (before insert, before update) { List<Account> accountsToUpdate = new List<Account>(); for (Account account : Trigger.new) { if (account.RunAssignment__c == TRUE) { // Find the territory using routing kew List<RoutingKey__c> routingkey = [select Name,Territory__c from RoutingKey__c where Name = :account.RoutingKey__c limit 1]; // if you found one if (routingkey.size() > 0) { //assign the territory account.Territory__c = routingkey[0].Territory__c; account.RunAssignment__c = FALSE; accountsToUpdate.add(account); } } } }
Also, when I try to deploy this trigger into prod using this class, I get a coverage error saying that there is no coverage at all even though I have 100% coverage in sandox.
@isTest private class AccountTerritoryTest { static testMethod void AccountTerritoryTest() { RoutingKey__c k = new RoutingKey__c(); k.Name = 'FL'; insert k; Account a = new Account(); a.Name = 'Test'; a.RoutingKey__c = 'FL'; a.RunAssignment__c = TRUE; insert a; a.RunAssignment__c = FALSE; update a; } }
I'm fairly new to coding and would greatly appreicate any help you could provide!
Let us know if this will help you
All Answers
Let us know if this will help you
Thank you for helping with the trigger! I still get errors when I try to validate this in production using the test class above. SFDC says that I have 0% coverage. Can you help?