0

new to apex and visualforce. I am trying to create a visualforce page that displays selected products and their locations for an order. Currently I am able to display the products selected for the order, however I can not figure out how to filter my query down to display only the product locations specific to the current order. I added the Shipment__c query to help look for products that are in shipments however I am getting the following error:

Error: Compile Error: Invalid bind expression type of Shipment__c for Id field of SObject Product2 at line 8 column 17

Any help would be appreciated.

My class is as follows:

public with sharing class ProductMovements {

Shipment__c[] sp = [Select (Select Project_Task__r.GMBLASERP__Product__r.Id From Shipment_Lines__r) From Shipment__c ];

Product2[] pp = [SELECT Id FROM Product2 WHERE Id IN :sp];

     public AggregateResult[] gim {
        get {
            return [SELECT GMBLASERP__Product__r.name name, GMBLASERP__Location__r.name location, SUM(GMBLASERP__Quantity__c) sum
                                                    FROM GMBLASERP__Inventory_Movement_Cube__c
                                                    WHERE GMBLASERP__Product__c IN :pp
                                                    GROUP BY GMBLASERP__Product__r.name, GMBLASERP__Location__r.name];
        }
    }
}
1
  • It's only dynamic soql if you build out query strings and use Database.query. You do none of that here, using only static queries. As such, I have removed the [dynamic-soql] tag.
    – Adrian Larson
    Jul 11, 2018 at 22:04

1 Answer 1

1

You will need to unpack the Product2Ids from the first SOQL query to then use them in a binding expression.

E.g.

Set<Id> product2Ids = new Set<Id>();
for(Shipment__c sp : [Select (Select Project_Task__r.GMBLASERP__Product__r.Id From Shipment_Lines__r) From Shipment__c ]) {
    product2Ids.add(sp.Project_Task__r.GMBLASERP__Product__r.Id);
}
Product2[] pp = [SELECT Id FROM Product2 WHERE Id IN :product2Ids];

That said, you could probably completely skip the Shipment__c records and go straight to the Shipment_Lines__c records with:

Select Project_Task__r.GMBLASERP__Product__r.Id From Shipment_Lines__c

If you can get it all the way down to whatever GMBLASERP__Product__c is it could make the query much simpler. You will likely need to add a where clause, but it should be much more efficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.