You need to sign in to do that
Don't have an account?
EvertonSzekeres
System.LimitException: Too many SOQL queries: 101 Data Loader Issue
I have an issue with dataloader while trying to load some records that fires the following trigger that gives me an error System.LimitException: Too many SOQL queries: 101 because of this issue:
Thanks,
trigger AtualizarAR_timba_task on Case (after update) { List<String> ids = new List <String> (); for (Case c: trigger.new) { if (Trigger.oldMap.get(c.id).Endere_o_pagamento__c != c.Endere_o_pagamento__c || Trigger.oldMap.get(c.id).Novas_altera_es__c != c.Novas_altera_es__c || Trigger.oldMap.get(c.id).Nome_completo_pagamento__c != c.Nome_completo_pagamento__c && (c.motivo__c == 'Formandos AR')){ ids.add(c.id); } Map<String, List<Task>> taskMap = new Map<String, List<Task>>(); for (Task t: [SELECT Id, whatid, subject, status, Aprovado__c, description FROM Task WHERE subject = 'AR - ImpressĂŁo aprovada?' AND status != 'ConcluĂdo' AND whatid =: ids]){ List<Task> taskList= new List<Task>(); if (taskMap.containsKey(t.whatid)){ taskList = taskMap.get(t.whatid); } if(c.Novas_altera_es__c != null){ t.Aprovado__c = 'NĂO'; t.status = 'ConcluĂdo'; } if(c.Nome_completo_pagamento__c != null && c.Endere_o_pagamento__c == null){ t.description = 'Nome da lombada = '+c.Nome_completo_pagamento__c+''; t.Aprovado__c = 'SIM'; t.status = 'ConcluĂdo'; } if(c.Nome_completo_pagamento__c != null && c.Endere_o_pagamento__c != null){ t.description = 'Nome da lombada = '+c.Nome_completo_pagamento__c+'\n\nNovo endereço = '+c.Endere_o_pagamento__c+''; t.Aprovado__c = 'SIM'; t.status = 'ConcluĂdo'; } taskList.add(t); taskMap.put(t.whatId, taskList); update(taskList); } } }I'll be glad if you can help me with rephrasing the SOQL query to be more efficient.
Thanks,
You need to bulkify your trigger by moving the SOQL query outside of your for loop.
See this post for a nice example of how to go about bulkifying your trigger:Â http://sfdc.arrowpointe.com/2008/09/13/bulkifying-a-trigger-an-example/
You can refer below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal