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

system.limitexception: too many query rows: 50001 in Production Instance
Hi,
For below trigger, when i have deployed in production, i am getting the "limit exception : too many query rows : 50001"
how can i fix this ?
For below trigger, when i have deployed in production, i am getting the "limit exception : too many query rows : 50001"
trigger TaskUpdatewithLeadComments on Task (after insert) { Set<Id> leadids = new Set<Id>(); List<Task> taskstoupdate = new list<Task>(); //Fetch only Leads which follow criteria for(Lead ld : [ SELECT Id, company FROM lead ]) { leadids.add(ld.Id); } //Iterate over all Leads and modify Tasks for them + Add to a list variable for(Lead ld : [SELECT Id, Prospect_notes__c,(SELECT Id, Whatid, Description FROM Tasks) from Lead Where Id IN : leadids]) { for(Task t : ld.Tasks) { if(t.Description==null) t.Description = ld.prospect_notes__c; taskstoupdate.add(t); } } //Update Tasks if(taskstoupdate.size()>0) { update taskstoupdate; } }
how can i fix this ?
All Answers
Please below code that will work
I have modified the trigger by adding additional WHERE clause the trigger is working fine in Production. As SOQL won't support querying long text fields, i created created field, which will be updated with workflow rule, if Prospect Notes (long text) field is not blank.
On the whole what i am trying to achieve is to autopopulate the Prospect Notes field from leads to the task created, if the comments(description) field in task is empty.(The prospect notes will be captured from Pardot in to Salesforce, when a prospect is uploaded/updated)
Any improvizaton in the below trigger is highly appreciated.
@ Marc - I will keep your suggestion in mind in my apex learning journey.