The following code works fine. The Id variable that I see in my debug log when I execute the code is the correct 18 digit Id.
List<Opportunity> psgPrimaryProjectIDToDelete = [Select pse__Primary_Project__c from Opportunity];
System.debug('***************PSG Primary Project Name is ' + psgPrimaryProjectIDToDelete[0]);
Id myId = psgPrimaryProjectIDToDelete[0].id;
System.debug('***********myId = ' + myId);
The problem occurs when I try to use that Id variable to return a result in my select statement that follows it. I keep getting the error: Expression cannot be a statement.
I get that error when I follow my working code with this:
[Select Id from PSG_Vendor_Order__c where PSG_Project__c = :myId];
Or with this:
Set<Id> s = new Set<Id>();
s.add(myId);
[Select Id from PSG_Vendor_Order__c where PSG_Project__c in :s;
The error shows up on the select statement but I have no idea why.... Can anyone help?
You need to actually build a new List you're not returning it correctly
List<PSG_Vendor_Order__c> psgVendorOrder = new List<PSG_Vendor_Order__c>([Select Id from PSG_Vendor_Order__c where PSG_Project__c = :myId]);