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
Sanchivan SivadasanSanchivan Sivadasan 

Invalid loop variable type expected ContentVersion was ContentVersion

Hi All, 
 
I am writing a trigger on ContentVersion in a Scratch Org and I have the below code working in a developer org, but it won't save in a Scratch org and I am getting the error "Variable does not exist: ContentDocumentId". The Trigger code is as follows:
trigger ContentVersionTrigger on ContentVersion (after insert) {
    Set<Id> contentDocumentIdSet = new Set<Id>();

    for(ContentVersion cv : Trigger.New) {
        contentDocumentIdSet.add(cv.ContentDocumentId);
    }
}
Also, if I comment out the code contentDocumentIdSet.add(cv.ContentDocumentId);

I get the following error:

"Invalid loop variable type expected ContentVersion was ContentVersion"

Does anyone know why?
Best Answer chosen by Sanchivan Sivadasan
Sanchivan SivadasanSanchivan Sivadasan
I tried it on another scratch org and it worked. So I went back to the original scratch org and deleted the trigger I created a new trigger and now it's working. That's strange.

All Answers

Sanchivan SivadasanSanchivan Sivadasan
I tried it on another scratch org and it worked. So I went back to the original scratch org and deleted the trigger I created a new trigger and now it's working. That's strange.
This was selected as the best answer
W Chad SmithW Chad Smith
I am seeing the same thing in a sandbox but related to OpportunityLineItem.  I've been doing this for 8 years and I've never seen anything like this.  Going to delete everything (Trigger & Utility class) and see if it fixes it.  Something is definitely odd.  
W Chad SmithW Chad Smith
My problem is I had a class named 'OpportunityLineItem' which I created by mistake instead of 'OpportunityLineItemUtility'.  Maybe you have a class or Trigger named ContentVersion in your scratch org.