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
swapna muthiyaluswapna muthiyalu 

contact object query

i have this query, select id, accountid, seccon__r.accountid from contact..
now how to write the same query to check if accountid is equal to  seccon__r.accountid ?
Best Answer chosen by swapna muthiyalu
Harish RamachandruniHarish Ramachandruni
HI, Please get all the data in to excel and add a filter it's not possible with a query because of we can't refer the same object filed no data is available while we are querying.

All Answers

Waqar Hussain SFWaqar Hussain SF
Create a formula field on contact object with return type of checkbox and which will return true if the contact's AccountId and contact's seccon__r.accountid are same.

Then you can query based on this formula field.
like
select id, accountid, seccon__r.accountid from contact where formula_field__c = true

 
swapna muthiyaluswapna muthiyalu
I can't create formula field
Harish RamachandruniHarish Ramachandruni
Hi,

You can use formula filed but you are saying it's not possible then you can go for this code.


 
List<Contact > Cons = new List<Contact>();


For (Contact cn:[select id,name,Accountid,seccon__r.Accountid from Account where Accountis != null and seccon__r.accountid != null]){


if(cn.accountid == seccoun__r.accountid){

Cons.add(cn);

}


}

Thanks,
Harish R
+919676930011.
swapna muthiyaluswapna muthiyalu
Harish Thank you so much, my requirement i just need to run query and pull data in dataloader, no need of list creation. Pls help.
Harish RamachandruniHarish Ramachandruni
HI, Please get all the data in to excel and add a filter it's not possible with a query because of we can't refer the same object filed no data is available while we are querying.
This was selected as the best answer