0

I've been looking around for awhile now trying to figure out how to fix this and I am unable to locate what could be wrong with this.

I am trying to create 2 objects, one that holds my Sampling Object and one that holds my Product Object. When I build my Sampling Object I want to get all the information where Responsible_for_EVB_Build1 is null so it can be populated from my Product object where it is usually not null. Am I going about this right or is my logic wrong?

List<Sampling__c> sampObj =([SELECT Product__c, Name,Id,Responsible_for_EVB_Build1__c FROM Sampling__c WHERE Responsible_for_EVB_Build1__c = null ]);               
system.debug('Product Object === ' +sampObj);

 List < Product2 > prodObj = new List<Product2>([Select Name,AE2__c From Product2 WHERE Id = : sampObj.Product__c]);        
    system.debug('1stParentsampObj === ' +prodObj);

1 Answer 1

1

This line is wrong I think:

List < Product2 > prodObj = new List<Product2>([Select Name,AE2__c From Product2 WHERE Id = : sampObj.Product__c]);        

sampObj is a list - so you can't filter where Id = on a list - you need to use an IN statement. You can try changing it to the line below so that it is filtering for all records IN the sampObj List - but depending on what the Product__c field is, you might need to loop through sampObj to build a unique set of Product Ids, and then filter for that instead

List < Product2 > prodObj = new List<Product2>([Select Name,AE2__c From Product2 WHERE Id IN :sampObj.Product__c]);    
5
  • Product__c is a Lookup field related to Product.
    – EricSSH
    Commented Mar 27, 2014 at 20:57
  • Something like this should work right? List < Product2 > prodObj = new List<Product2>([Select Name,AE2__c From Product2 WHERE Id IN :[SELECT Product__c,Id,Name From Sampling__c]]);
    – EricSSH
    Commented Mar 27, 2014 at 21:08
  • 1
    Maybe - but I think you'd be better to query for a unique set of Product Ids Commented Mar 27, 2014 at 22:50
  • I ended up Nuking it and starting over, I will try it that way
    – EricSSH
    Commented Mar 27, 2014 at 22:54
  • Finished it.. works perfect, good suggestion BritishBoy
    – EricSSH
    Commented Mar 28, 2014 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .