0

Internal user send email to create case in SFDC, but after case creation, when user try to reply (custom VF page) it throws

System.LimitException: Too many query roews: 50001 error.

As per log I found following place failing this.

12:51:52.954 (10954390113)|WF_TIME_TRIGGERS_BEGIN
12:51:52.985 (10985366852)|WF_ACTIONS_END| Field Update: 3;
12:51:52.985 (10985380079)|CODE_UNIT_FINISHED|Workflow:Case
12:51:53.017 (11017072469)|CODE_UNIT_STARTED|[EXTERNAL]|01qd0000000CCo9|Implementation_Attachment_Validation on Attachment trigger event BeforeInsert for [new, new, new]
12:51:53.017 (11017424883)|SYSTEM_METHOD_ENTRY|[15]|Schema.SObjectType.getDescribe()
12:51:53.017 (11017644157)|SYSTEM_METHOD_EXIT|[15]|Schema.SObjectType.getDescribe()
12:51:53.017 (11017902683)|SOQL_EXECUTE_BEGIN|[19]|Aggregations:0|SELECT Id, Name FROM Profile
12:51:53.021 (11021453266)|SOQL_EXECUTE_END|[19]|Rows:18
12:51:53.021 (11021495775)|EXCEPTION_THROWN|[19]|System.LimitException: Too many query rows: 50001
12:51:53.021 (11021701367)|FATAL_ERROR|System.LimitException: Too many query rows: 50001

Trigger.Implementation_Attachment_Validation: line 19, column 1
12:51:53.021 (11021719453)|FATAL_ERROR|System.LimitException: Too many query rows: 50001

Trigger.Implementation_Attachment_Validation: line 19, column 1
12:51:53.021 (11021801622)|CUMULATIVE_LIMIT_USAGE
12:51:53.021 (11021801622)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 42 out of 100
  Number of query rows: 50001 out of 50000 ******* CLOSE TO LIMIT

here is the trigger per log above.

I need you help to find the solution to this.

trigger Implementation_Attachment_Validation on Attachment (before delete, before insert, before update) {

    Schema.Describesobjectresult dsor = schema.Sobjecttype.Implementation__c;
    Map<Id, Profile> profMap = new Map<Id, Profile>();
    Map<Id, User> usMap = new Map<Id, User>();

    Profile[] profList = [Select Id, Name from Profile];

    for(Profile pr:profList) {
        profMap.put(pr.Id, pr);
    }


    if(Trigger.IsDelete)
    {
      for(Attachment att: Trigger.old)
        {
            String parentId = (String)att.parentId;
            if(parentId.substring(0,3) == dsor.getKeyPrefix())
            {
                if(profMap.get(UserInfo.getProfileId()).Name != 'System Administrator' && profMap.get(UserInfo.getProfileId()).Name !='7ticks Finance User')
                //if(profMap.get(UserInfo.getProfileId()).Name != 'System Administrator')
                {
                    att.addError('Attachment cannot be deleted.');
                }
            }   
        }
      }

    if(Trigger.IsBefore && Trigger.IsInsert)
    {
         for(Attachment att: Trigger.New)
        {
            String parentId = (String)att.parentId;
            if(parentId.substring(0,3) == dsor.getKeyPrefix())
            {
                if(profMap.get(UserInfo.getProfileId()).Name != 'System Administrator')
                {
                    att.IsPrivate = false;
                }
            }
        }
    }

    if(Trigger.IsBefore && Trigger.IsUpdate)
    {
       for(Attachment at: Trigger.New)
        {
            String parentId = (String)at.parentId;
            if(parentId.substring(0,3) == dsor.getKeyPrefix())
            {
                if(profMap.get(UserInfo.getProfileId()).Name != 'System Administrator')
                {
                    at.addError('Attachment cannot be updated');
                }
            }   
        }
     }
}
  • 1
    You've run 42 queries total at the time you hit this limit. The query in this trigger only returned 18 rows. Look earlier in your log to see what queries were returning large numbers of results and why there were 40+ queries before hitting this trigger. – crmprogdev Sep 17 '15 at 16:21
1

Try to filter on cases using where clause [better to have indexed fields]:

List accounts=[select id,name,Last_Outbound_Email_Time__c,(select Last_Outbound_Email_Time__c from cases where status = 'Open') from Account where id IN :accountIds];

Hope it helps.

-1

I believe this trigger is not at fault. Your query is only pulling 18 rows.

Please check your entire debug log.

Other triggers which are executing prior to this trigger maybe eating your query rows.

You can check the number of rows returned by each query in Developer console or manually (in the line after the query)

  • if you filter the debug logs (in Dev Console for example) with "SOQL_EXECUTE_END" you should be able to see all SOQL queries that executed in the transaction and find the one(s) that return the large result sets. Probably a query in a for-loop that needs to be bulkified. – AlwaysThinkin Sep 17 '15 at 15:28
  • Limited knowledge as Developer. I went through log per your direction but did not find much. Posting log here hope that will help you find some clue. – Sunny Sep 17 '15 at 15:34
  • I am afraid I am only able to see a part of the debug log which seems to be of very little help. A full log will help analyse the issue. – manjit5190 Sep 17 '15 at 16:21
  • Found the issue: One of the class running following query which pull case related to a particulate account. In our case we have close to 50K cases. List<Account> accounts=[select id,name,Last_Outbound_Email_Time__c,(select Last_Outbound_Email_Time__c from cases) from Account where id IN :accountIds]; how we can optimize this query now any help ? – Sunny Sep 17 '15 at 18:56
  • 1
    Try to comment when you don't know the problem but are helping troubleshoot. – Samuel De Rycke Sep 22 '15 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.