• Michael Brumley
  • NEWBIE
  • 55 Points
  • Member since 2009
  • Salesforce Solution Lead
  • Accelerize360

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 10
    Replies

I'm writing what should be a simple Apex class to determine if a Lead being added already exists as an Account. To do this, I need to check for matching email addresses between the Lead and the Account Contacts, and matching company names and zip codes between the Account and the Lead. They have very little data in their sandbox, so I tested the best I could in my dev account, and had 92% coverage on the class with no errors. Right after deployment though, two of the queries started exceeding governor limits, in ways that just don't make sense to me.  (I'm still waiting on specific data to recreate.) Here's the first, which generates a "Too many query rows:1001" exception.

 

if (TestLead.Email != null) { // Nested query returns accounts having contacts with matching emails Account[] emailAccts = [SELECT AccountNumber, Account_Activity__c FROM Account WHERE ID in (SELECT AccountID FROM Contact WHERE Email = :TestLead.Email)]; if (!emailAccts.isEmpty()) { bFoundExact = true; sExactType = emailAccts[0].Account_Activity__c; } }

 

 

The error column is 30, which is the beginning of the outer Select - does that mean it's the number of Account records that's too large? If so, is my problem related to the IN working on all the empty result sets the inner query will return? If that's not it, ...?

 

The second error is even more of a mystery, it's "Non-selective query against large object type (more than 100000 rows)." Here's the query:

 

for (Contact zipContact : [SELECT Account.Type, Email FROM Contact WHERE Account.BillingPostalCode = :TestLead.PostalCode]) { ContactDomain = DomainPart(zipContact.Email); if (ContactDomain == LeadDomain) // Partial match { bFoundPartial = true; sPartialType = zipContact.Account.Type; break; } }

 

 

Ok, so I get that the zip codes probably aren't indexed fields so it's got to check all the records, and they do have 50k accounts, but 1 million contacts still seems a bit unlikely. Any idea what I'm doing wrong? How do I read that message - that the result set has too many rows, or that the object being queried on a non-indexed field has too many?

 

Finally, I've searched high & low and can't find out how to tell which fields in an object are indexed, could someone kindly point me in the right direction?

 

Thanks,

Mike Brumley

 

i need to query two values stored in my custom field in my query dynamically 

In my custom object i am having custom field that stores single value like XYZ or multiple values like xyz,ABC now i need to query both values how?
Hi, 

 Below trigger on case is not firing when case is created via email. Please suggest me how to fix thi issue.
Trigger
======
trigger CaseTrigger on Case (Before Insert){

   CaseTriggerUtils.processInsert(Trigger.new);

}


Class
=====
public class CaseTriggerUtils {
    
    public static void processInsert(list<Case> cseLst) {        
        processCase(cseLst, new Set<String>{'FW:', 'RE:', 'RW:'});  //Keywords are passed     
    }   
   
 public static void processCase(list<Case> cseLst, Set<String> keyWords) {
        String CaseSubject;
        String CaseId;
        String CaseOwnr;
       
        Map<String, List<String>> keyWordSubjectListMap = new Map<String,List<String>>();
        list<Case> caseLst = new list<Case>();
       
        for (Case c : cseLst) {    
            CaseId = c.id;   
            if(c.subject <> null){
                for(String keyWord : keyWords) {
                    if(c.Subject.contains(keyWord)) {
                        CaseSubject = c.subject.replaceAll(keyWord,'');
                        List<String> subjectList = keyWordSubjectListMap.containsKey(keyWord) ?
                        keyWordSubjectListMap.get(keyWord) : new List<String>();
                        subjectList.add(CaseSubject);
                        keyWordSubjectListMap.put(keyWord, subjectList);
                        break;
                    }
                     if(CaseSubject == null)  
                       CaseSubject = c.subject;
                }
            }
        }
        System.debug('Case Subject' +  CaseSubject);
        System.debug('MAP' + keyWordSubjectListMap);
        
       list<case> cseQry = [select id, casenumber,subject,createddate,ownerid,owner.name from case where CreatedDate = this_year and id <> :CaseId and subject like :('%' + CaseSubject + '%') order by createddate asc limit 10];
        //system.debug('Existing Cases :'  + cs.casenumber + ' ' + cs.subject + ' ' + cs.createddate + ' ' + cs.owner.name); 
        
       for(Case cs: cseLst){     
         if(!cseQry.isEmpty()){  
           if(cs.ownerid <> cseQry[0].ownerid)   // if owner is different from the current owner, then update the owner and set duplicate flag.
             cs.ownerid = cseQry[0].ownerid;   
             cs.Duplicate_With__c = cseQry[0].casenumber;   
           if ( cs.subject.length() > 18 ){    //keyword check is more than 18 character remove keyword and save.
              cs.subject = CaseSubject;
            } 
          }     
       }
        
 }
    
}
Thanks
GMASJ
 
  • March 05, 2019
  • Like
  • 0
Hello,

When a task is created I update a lookup field with the whoID if the whoID is a contact that is. However, when someone sends an email it does not fire the trigger. Apparently this is because it creates an object called EmailMessage and not just a Task, well it also creates a Task. The problem that arises is that when the task is created it is being done by an internal flow so it does not fire my trigger. Okay no problem, then I need to move my trigger to fire when the EmailMessage is created. Then I run into the issue of I don't know how to query for the task created that is associated with this email message to update the fields on the task accordingly. Any help would be much appreciated.
Hello everyone, I successfully create a form of record views of users and now cannot deploy in my production org without a test class. I've searched all day for a sample test that can help explain what I am to do, no luck!

Here is my class code:
 
public class lastViewed{
 
    public Datetime cDT; 
    public String LongDate; 
    public String firstname; 
    public String lastname;    
    public String userid;
 
    private final Chalkboard_Manager__c acct;
 
    public lastViewed(ApexPages.StandardController stdController) {
        this.acct = (Chalkboard_Manager__c)stdController.getRecord();    }
 
                public String getLongDate() {        
                cDT = System.now();        //Format the datetime value to your locale        
                LongDate = cDT.format('dd/MM/yyyy HH:mm');    return LongDate;    
            }
 
        public void updateField() {
        //Get the user info from the current user        
    firstname = System.Userinfo.getFirstName();        
    lastname = System.Userinfo.getLastName();       
    userid = System.Userinfo.getUserId();
 
        //Get the chalkboard record to be updated        
    Chalkboard_Manager__c a = [select Last_Viewed_By__c from Chalkboard_Manager__c where id = :acct.id limit 1];        
 
    //Assign values to Last Viewed By field & update the record        
    a.Last_Viewed_By__c = (firstname + ' ' + lastname + ', ' + getLongDate());        
    update a;    
    }
 
}

 
Universal con needs a field on the account to track how many opportunities are closing within the next 30 days. What can be used?

A. Workflow rule
B. Roll-up summary field
C. Process builder
D. Apex code

I'm writing what should be a simple Apex class to determine if a Lead being added already exists as an Account. To do this, I need to check for matching email addresses between the Lead and the Account Contacts, and matching company names and zip codes between the Account and the Lead. They have very little data in their sandbox, so I tested the best I could in my dev account, and had 92% coverage on the class with no errors. Right after deployment though, two of the queries started exceeding governor limits, in ways that just don't make sense to me.  (I'm still waiting on specific data to recreate.) Here's the first, which generates a "Too many query rows:1001" exception.

 

if (TestLead.Email != null) { // Nested query returns accounts having contacts with matching emails Account[] emailAccts = [SELECT AccountNumber, Account_Activity__c FROM Account WHERE ID in (SELECT AccountID FROM Contact WHERE Email = :TestLead.Email)]; if (!emailAccts.isEmpty()) { bFoundExact = true; sExactType = emailAccts[0].Account_Activity__c; } }

 

 

The error column is 30, which is the beginning of the outer Select - does that mean it's the number of Account records that's too large? If so, is my problem related to the IN working on all the empty result sets the inner query will return? If that's not it, ...?

 

The second error is even more of a mystery, it's "Non-selective query against large object type (more than 100000 rows)." Here's the query:

 

for (Contact zipContact : [SELECT Account.Type, Email FROM Contact WHERE Account.BillingPostalCode = :TestLead.PostalCode]) { ContactDomain = DomainPart(zipContact.Email); if (ContactDomain == LeadDomain) // Partial match { bFoundPartial = true; sPartialType = zipContact.Account.Type; break; } }

 

 

Ok, so I get that the zip codes probably aren't indexed fields so it's got to check all the records, and they do have 50k accounts, but 1 million contacts still seems a bit unlikely. Any idea what I'm doing wrong? How do I read that message - that the result set has too many rows, or that the object being queried on a non-indexed field has too many?

 

Finally, I've searched high & low and can't find out how to tell which fields in an object are indexed, could someone kindly point me in the right direction?

 

Thanks,

Mike Brumley