You need to sign in to do that
Don't have an account?

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 salesops@imperva.com');
isValid = false;
}
}
// 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 salesops@imperva.com');
isValid = false;
}
}
You have to access the relationship with an __r instead of __c so:
Regional_Sales_Director__r.Name
It doesn't look like this code is bulkified. There are plenty of articles how and why to do it.