You need to sign in to do that
Don't have an account?
Non-selective query against large object type salesforce
Hi
Here is my code.
list<Contact> ContactMap1=[Select Id,Email from Contact where Email IN :EmailSet1];
for(Contact k:ContactMap1){
Map_Contact_To_Id.put(k.Email,k.Id);
}
list<Campaign> theCampaign = [SELECT Id, Name FROM Campaign WHERE Name IN :CampaignList OR Id IN :SfCampaignList];
for (Campaign k:theCampaign) {
Map_CampaignName_To_Id.put(k.Name,k.Id);
Map_CampaignId_To_Id.put(k.Id,k.Id);
}
for (CnP_Transaction__c c : Trigger.new) {
if(c.sf_Campaign__c == null)
c.sf_Campaign__c=Map_CampaignName_To_Id.get(c.Campaign__c);
}
list<CampaignMember> ListMemebers=new list<CampaignMember>();
CampaignMember CreateMem=new CampaignMember();
for (CnP_Transaction__c c : Trigger.new) {
campMembers(c.sf_Campaign__c);
if((c.sf_Campaign__c!=null || c.Campaign__c!= null)&&Map_CamId_ConId.get(c.sf_Campaign__c)!=c.Contact__c){
CreateMem = new CampaignMember(Campaignid=Map_CampaignId_To_Id.get(c.sf_Campaign__c), Contactid=c.Contact__c, Status='Received');
Map_CamId_ConId.put(Map_CampaignId_To_Id.get(c.sf_Campaign__c),Map_Contact_To_Id.get(c.Email__c));
ListMemebers.add(CreateMem);
}
}
if(ListMemebers.size()>0){
insert ListMemebers;
}
public void campMembers(String CampaignId1){
List<CampaignMember> campmem = [select contact.Email,Campaignid,Contactid from CampaignMember where CampaignId!=null];
for(CampaignMember cm :campmem){
if(cm.CampaignId == CampaignId1)
Map_CamId_ConId.put(cm.ContactId,cm.CampaignId);
}
One of my client getting the following error because of my code:
Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CnP_PaaS.addCorresCont: execution of BeforeInsert
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows)
Consider an index filter.
My doubt is they are getting the error because of that query(which is in bold).
How can I solve that??
Please help
Thanks
Anu
I think you need to look at this reference:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm
When an object exceeds 100k rows, you have to follow the guidelines above - and filtering by != null is not considered selective.
Looking at that query, why can't you filter for the CampaignId you pass in as a parameter - it looks like you only care about members with that Id? Id fields are indexed, so would most likely fulfil the selective query requirements
All Answers
Hi,
You are getting this error because you can query till max of 50000 records through and SOQL. Hence either you make to make a limit inside your SOQL or you have to use batch apex.For batch apex please go through this:
http://developer.force.com/cookbook/recipe/using-batch-apex-to-reassign-account-owners
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I think you need to look at this reference:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm
When an object exceeds 100k rows, you have to follow the guidelines above - and filtering by != null is not considered selective.
Looking at that query, why can't you filter for the CampaignId you pass in as a parameter - it looks like you only care about members with that Id? Id fields are indexed, so would most likely fulfil the selective query requirements