function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bill ButtonBill Button 

Count number of records returned

Hi,
 
How to check number of records returned. Currentrly when I try to make "if (AssignmentRegionOnly = 1) {" it errors with condition expression must be of type Boolean.
 
 
 for (Lead a : Trigger.new) {
  integer AssignmentRegionOnly = [select Count() from Assignment__c where Country__c = :a.Country and State_County__c = :a.State];
  if (AssignmentRegionOnly > 0) {
   Assignment__c AssignThis = [select Area_Account_Manager__c,Reseller__c from Assignment__c where Country__c = :a.Country and State_County__c = :a.State];
   SendEmail = 1;
   a.OwnerId = AssignThis.Area_Account_Manager__c;
   if (AssignThis.Reseller__c != null ) {
    a.Reseller__C = AssignThis.Reseller__C;
    SendToReseller = 1;
   }
  }
  else {
   integer AssignmentRules = [select Count() from Assignment__c where Country__c = :a.Country];
   if (AssignmentRules > 0) {
    Assignment__c AssignThis = [select Area_Account_Manager__c,Reseller__c from Assignment__c where Country__c = :a.Country];
    a.OwnerId = AssignThis.Area_Account_Manager__c;
    SendEmail = 1;
    if (AssignThis.Reseller__c != null ) {
     a.Reseller__C = AssignThis.Reseller__C;
     SendToReseller = 1;
    }
   }
   else {
    //
    // No Match Found need to assign to Lead Queue
    //
    a.OwnerID = '00G20000000qGsmEAE';
    SendEmail = 1;
    SendToReseller = 0;
   }
  }
 
Thanks
Bill
 
SuperfellSuperfell
if (AssignmentRegionOnly == 1) {

note the extra = character
Bill ButtonBill Button

Hi Simon,

Thanks for the help, I have also just put a nice dent in the wall with my forehead for being dumb

Thanks

Bill