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
Jyoti TrailheadJyoti Trailhead 

Contact record query

I am trying to run this code in Anonymous window:

List<Contact> ConList = New List<Contact>();
ConList = [Select id, name, Account.name, Parent_Account__r.name from Contact where Parent_Account__r.name != Account.Parent.name];
System.debug('Contact records :    ' + Con1);

getting error:

Line: 2, Column: 9
Unexpected token '='.

I need to run below query in Dev console or workbench to get the contact records where Parent Account on Contact is not equal to Parent Account of Account:

select id, name, Account.name, Parent_Account__r.name,(Select id,name, Parent.name from Account) from Contact where Parent_Account__r.name != Account.Parent.name

Please help

 
FARSANA PSFARSANA PS
hi,
 can you explain Parent_Account__r.name in your query...
Jyoti TrailheadJyoti Trailhead
Now this error: Line: 2, Column: 11 Invalid bind expression type of Schema.SObjectField for column of type String Regards Jyoti
Steven NsubugaSteven Nsubuga
I was wrong, this scenario is not possible in SOQL..
The workaround is to use a checkbox formula field on the Contact object.
Parent_Account__r.name != Account.Parent.name
Then you use this formula field in the where clause of your SOQL query.