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
dash27dash27 

Querying where object in list

I have a trigger that wants to create a list of all the ids of the triggering object.  I initially tried this:

list<id> accIds = [select id from Account where Account in: trigger.new];

 but that doesn't compile.

 

Is there a way to do this without using a for loop an iterating over all the objects in the trigger.new list?

Bhawani SharmaBhawani Sharma
You can simply use Trigger.newMap for this.
Set<Id> accIds = Trigger.newMap.keySet();
Avidev9Avidev9

Yes just change the code lil bit.

 

List<Id> accIds = trigger.newMap.keyset();

 The above works for after insert , before update,after update nad not for delete because trigger.new doesnt exists for delete trigger.

sushant sussushant sus
you can try this
List<Id> accIds = trigger.newMap.keyset();

or
list<id>ids=newlist<id>();
for(account a: trigger.new)
{
ids.add(a.id)
}