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

soql in validation class to compare field values

So here is my issue. I have a class that does a validation to check if things are oaky before user can convert the lead. What i am trying to do is check to see if the RSD ID listed on the territory object matches the Assigned to ID on the QSL object. Below is the code i have thus far but keep getting relationship error. can anyone help

// North America Territory assignment
     if (this.lead.Territory__c.Name == 'NA -*'){
      RSD = [Select ID,Regional_Sales_Director__c.Name from Territory__c where ID := Territory__c.Id];
      primeQ = [Select ID, Assigned_To__c.Name From QSL_Review_Request__c Where ID := QSL_Review_Request__c.ID];
      if (!isMatch(primeQ)){
       addError('Please update the lead owner to the correct queue. If this is a PRM lead or you need help, contact');
       isValid = false;
Florian HoehnFlorian Hoehn

You have to access the relationship with an __r instead of __c so:


It doesn't look like this code is bulkified. There are plenty of articles how and why to do it.