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
AnshulVermaAnshulVerma 

Selecting Objects by placing ID field in IN Clause of SOQL

Hi,

I want to search certain objects based on the ID's that have been stored in a string (coma separated), as we do in SQL

SELECT <fields> FROM <Table_name> WHERE ID IN ( <Comma seperated ID's> ).

I have tried to do the same in SOQL but didn't succeed in doing so. Although, when i execute the SOQL query in SOQL Explorer it runs fine and returns correct data back.

-> Secondly, while searching for probable solutions, I found the concept of Polymorphic keys in Salesforce. But, I was not able to find much data on that. Can somebody please give more information on that.

Any help would be apreciated.

Thanks,
AV
tmatthiesentmatthiesen
Per the docs:

-----
// An IN-bind with an Id list. Note that a list of sObjects
// can also be used--the Ids of the objects are used for
// the bind
Contact[] cc = [select id from contact limit 2];
Task[] tt = [select id from task where whoId in :cc];

// An IN-bind with a String list
String[] ss = new String[]{'a', 'b'};
Account[] aa = [select id from account where accountnumber in :ss];
-----

What is the requirement you are looking to support with polymorphic keys?
AnshulVermaAnshulVerma

Hi,

Following is my requirement. I have to register various alerts on modifications of a Case, Comapany etc., so i have a custom object named "ActionAlert". So, each time i do something on Case, Company or other i would save a new recordin ActionAlerts and would be displayed to the concerned users. Now, the ActionAlert has a field RecordID (pointing to record to which it pertains like Case, Company etc.).

So, this RecordID field is a reference field which references to multiple objects.

Please explain how to achieve this??

A.V.