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
Jonathan Wolff 7Jonathan Wolff 7 

Error in Apex trigger code: IN operator must be used with an iterable expression

Hello, a developer helped me creating a apex trigger, but i still have the error: IN operator must be used with an iterable expression 
Could you tell me how to fix this error? :)
 
trigger ContentDocumentIdTrigger on ContentDocumentLink(after insert){

map<id,id> parentids = new map<id,id>();

for(ContentDocumentLink cdl:trigger.new){
parentids.put(cdl.LinkedEntityId,cdl.ContentDocumentId);
}

List<Mediathek__c> ContentDocumentIdupdate = new List<Mediathek__c>();

for(Mediathek__c mt:[select id, from Mediathek__c where id IN:parentids]){

if(parentids.containskey(mt.id)){
mt.ContentDocumentID__c = parentids.get(mt.id);
ContentDocumentIdupdate.add(mt);
}
}
update ContentDocumentIdupdate;
}

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Jonathan,

try with below code.
trigger ContentDocumentIdTrigger on ContentDocumentLink(after insert){

map<id,id> parentids = new map<id,id>();

for(ContentDocumentLink cdl:trigger.new){
parentids.put(cdl.LinkedEntityId,cdl.ContentDocumentId);
}

List<Mediathek__c> ContentDocumentIdupdate = new List<Mediathek__c>();

for(Mediathek__c mt:[select id, from Mediathek__c where id IN:parentids]){

if(parentids.containskey(mt.id)){
mt.ContentDocumentID__c = parentids.get(mt.id);
ContentDocumentIdupdate.add(mt);
}
}
update ContentDocumentIdupdate;
}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​