You need to sign in to do that
Don't have an account?
lakshmi.sf9
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Hi,
I written one batch class,and schedular class.From trigger I am calling these two calsses.
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5){
database.executebatch(updateContact,200);
}
else{
scheduledupdateContactOwner sc = new scheduledupdateContactOwner(UpdateContacts);
Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
Id schedId = System.Schedule('ContactOwnerUpdate'+timeForScheduler,timeForScheduler,sc);
}
But i am getting below error In the below Query
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5)
If I run this query with out filters also results are less than 800.If I seacrh in google In every post inframtion is need to give more filters.
Can anyone expalin how to solve this issue..
Thanks in advance,
I written one batch class,and schedular class.From trigger I am calling these two calsses.
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5){
database.executebatch(updateContact,200);
}
else{
scheduledupdateContactOwner sc = new scheduledupdateContactOwner(UpdateContacts);
Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
Id schedId = System.Schedule('ContactOwnerUpdate'+timeForScheduler,timeForScheduler,sc);
}
But i am getting below error In the below Query
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5)
If I run this query with out filters also results are less than 800.If I seacrh in google In every post inframtion is need to give more filters.
Can anyone expalin how to solve this issue..
Thanks in advance,
Identify 'updateContact' class have any select statements to return more data, if yes use the limits and put the where conditions possible.
The issue is throwing internal classes execution rather than if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5).
It isn't necessary. You should be interested in jobs that were created last time. So, try to limit amount of AsyncApexJob records by using WHERE condition for CreatedDate. For example, for last 5 days:
here is my code
-------Triggers-------------
{
for(Account currentAcc:Trigger.new){
A.Triggers.AccountUpdateContactowner.init(currentAcc,Trigger.oldmap.get(currentAcc.id));
}
A.Triggers.AccountUpdateContactowner.Process(Trigger.new);
}
------class----------
public void Init(Account currentAccount,Account previousAccount) {
if( currentAccount.OwnerId != previousAccount.OwnerId && !currentAccount.IsPersonAccount){
accountMap.put(currentAccount.id,currentAccount.ownerid);
}
}
public List<Account> Process(List<Account> Accounts) {
list<Contact> UpdateContacts = new list<Contact>();
list<Contact> batchUpdateContacts = new list<Contact>();
if(!accountMap.isempty()){
for(Contact c: [select Id, OwnerId, AccountId from Contact where AccountId IN :accountMap.keySet() ]) {
c.OwnerId = accountMap.get(c.AccountId);
UpdateContacts.add(c);
}
DateTime today = system.now();
updateContactOwner updateContact = new updateContactOwner(UpdateContacts);
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5){
database.executebatch(updateContact,200);
}
else{
scheduledupdateContactOwner sc = new scheduledupdateContactOwner(UpdateContacts);
Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
Id schedId = System.Schedule('ContactOwnerUpdate'+timeForScheduler,timeForScheduler,sc);
}
UpdateContacts.clear();
}
return Accounts;
}
---batch class----------
global class updateContactOwner implements Database.Batchable<Contact>{
global List<Contact> contactRecords = new List<Contact>();
global updateContactOwner(List<Contact> contactList){
contactRecords = contactList;
}
global Iterable<Contact> start(database.batchablecontext BC){
return (contactRecords);
}
global void execute(Database.BatchableContext BC, List<Contact> scope){
set<id> ids = new set<id>();
List<Contact> contactList = new List<Contact>();
for(Contact c : contactRecords){
ids.add(c.AccountId);
}
for(Id i : ids ){
for(Contact c : scope){
if(c.AccountId == i){
contactList.add(c);
}
}
update contactList;
contactList.clear();
}
}
global void finish(Database.BatchableContext BC){
}
}
SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')
If I exucute below query results are 275365
SELECT count() FROM AsyncApexJob
If I exceute below query results are 766
SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex'
DateTime lastTwoDays = DateTime.now().addDays(-2);
if ([SELECT count() FROM AsyncApexJob WHERE CreatedDate >:lastTwoDays AND JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5){
}
Still it is not working...
It seems that exception is thrown in different place. Look at the line of code before:
And try to find any SOQL statements inside class UpdateContactOwner as Nbk user suggested. It could be cause of your trouble.
But I am not using soql Queries in updateContactOwner class.Just passing contatc records list .I posted my code in last two posts back..
Please check and suggest to me.
But again same error............
Sometimes it is really hard to create the selective query.
Make sure that exception take place in this query and not in different part of your code. Just for double check.
Maybe the following SOQL query will help: