You need to sign in to do that
Don't have an account?
Carter85
Help with query not populating a list.
I'm puzzled as to why a query I'm working on is not returning any results, particularly when I tested the same query in the DataLoader as first to check that it would pull the results I wanted. My class and method are below:
public with sharing class CM_ContractStatusUpdate{
public CM_ContractStatusUpdate(){
}
public void updateContracts(){
List<MG_Contract_Holder__c> statUpd = new List<MG_Contract_Holder__c>();
statUpd = [SELECT ID FROM MG_Contract_Holder__c WHERE Contract_Status__c = 'Active' AND Expiration_Date__c < TODAY LIMIT 99];
if(statUpd.size() > 0){
for(Integer i = 0; i < statUpd.size(); i ++){
MG_Contract_Holder__c upd = [SELECT Contract_Status__c FROM MG_Contract_Holder__c WHERE ID =:statUpd[i].ID];
upd.Contract_Status__c = 'Canceled';
update upd;
}
}
}
}
However, each time I run it the statUpd list fails to populate, even though my tests with the DataLoader returned the results I was expecting. Would appreciate any thoughts on the error.
public with sharing class CM_ContractStatusUpdate{
public CM_ContractStatusUpdate(){
}
public void updateContracts(){
List<MG_Contract_Holder__c> statUpd = new List<MG_Contract_Holder__c>();
statUpd = [SELECT ID FROM MG_Contract_Holder__c WHERE Contract_Status__c = 'Active' AND Expiration_Date__c < TODAY LIMIT 99];
if(statUpd.size() > 0){
for(Integer i = 0; i < statUpd.size(); i ++){
MG_Contract_Holder__c upd = [SELECT Contract_Status__c FROM MG_Contract_Holder__c WHERE ID =:statUpd[i].ID];
upd.Contract_Status__c = 'Canceled';
update upd;
}
}
}
}
However, each time I run it the statUpd list fails to populate, even though my tests with the DataLoader returned the results I was expecting. Would appreciate any thoughts on the error.
Please try one by one following things and see if you are getting results:
1. Remove with sharing from class and execute the code.
2. Remove Expiration_Date__c < TODAY filter and execute code.
You will come to know the cause of this behaviour.