Solved

SOQL query with Lead Owner

  • 5 December 2017
  • 3 replies
  • 34 views

I am building a SOQL query that pulls Lead information from many records, to populate a Word document template. I am trying to filter the data by Owner. I can't seem to figure out how to name the owner field so that it is recognized both by DocGen and by SalesForce. I've tried Owner.Name and many other things, and they either aren't recognized by DocGen, cause a metadata error, or simply don't return any results when I run the report. 

 

Any ideas? Thanks in advance. 

 

Here's the specific query: 

 

SELECT Owner.Name, Company, RecordTypeId, Name, Project_Request_Description__c, NYBC_Contact_Name__c, Clinical_Trial__c, Geographic_Site__c, Operational_area__c, R_D_Area__c, Business_Model__c, On_hold__c, Lead_Stage__c, Status, (SELECT ActivityDate, Subject, Description FROM Events ORDER BY ActivityDate DESC LIMIT 1) FROM Lead WHERE (Status!=(’Sent to Operations’ OR ‘Qualified’ OR ‘Unqualified’) AND  RecordType.Name=’Research_Services_Lead' AND Internal_Contact__c!='Person1' AND LastName!=’no name’ AND Owner.Name!=(‘Person2’ OR ‘Person3’) ORDER BY On_hold__c

icon

Best answer by ryan_oleary 7 December 2017, 23:15

View original

3 replies

UPDATE: I used the Developer Console to debug the above query, so now it works in the Console, but it doesn't work as a SOQL inquiry in DocGen. I get a metadata error when I run the report. 

SELECT Owner.Name, Company, RecordTypeId, Name, Project_Request_Description__c, NYBC_Contact_Name__c, Clinical_Trial__c, Geographic_Site__c, Operational_area__c, R_D_Area__c, Business_Model__c, On_hold__c, Lead_Stage__c, Status, (SELECT ActivityDate, Subject, Description FROM Events ORDER BY ActivityDate DESC LIMIT 1)

FROM Lead

WHERE (Owner.Name!='Person1' AND Owner.Name!='Person2' AND Owner.Name!='Person3' AND Owner.Name!='Person4' AND Owner.Name!='Person5' AND RecordTypeId='012E0000000fOEuIAM' AND Status!='Sent to Operations' AND Status!='Qualified' AND Status!='Unqualified' AND Name!='no name' AND NYBC_Contact_Name__c!='Person6')

ORDER BY On_hold__c

I am told there is some way to run the query directly from Developer Console, and DocGen can somehow reference this when it is generating a document package. If that's the only way to proceed, that's fine - although I can't find documentation on how. Any advice would be appreciated.

Userlevel 4
Badge +8

Hey Rick,

If I had to guess, looking at the query I would guess it's due to the line spaces in the query. Please try the below query:

SELECT Owner.Name, Company, RecordTypeId, Name, Project_Request_Description__c, NYBC_Contact_Name__c, Clinical_Trial__c, Geographic_Site__c, Operational_area__c, R_D_Area__c, Business_Model__c, On_hold__c, Lead_Stage__c, Status, (SELECT ActivityDate, Subject, Description FROM Events ORDER BY ActivityDate DESC LIMIT 1) FROM Lead WHERE (Owner.Name!='Person1' AND Owner.Name!='Person2' AND Owner.Name!='Person3' AND Owner.Name!='Person4' AND Owner.Name!='Person5' AND RecordTypeId='012E0000000fOEuIAM' AND Status!='Sent to Operations' AND Status!='Qualified' AND Status!='Unqualified' AND Name!='no name' AND NYBC_Contact_Name__c!='Person6') ORDER BY On_hold__c

Cheers,

Ryan

Yes this worked! Thank you very much. 

Reply