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 LordJonathan Lord 

Use result of one SOQL query for another

Hi,

I have a requirement to set the Pricebook on the Opportunity but want to be able to do it with one SOQL query if possible.

From the Opportunity I can get the Campaign.PFC_Product_Name__c Id which I then want to be able to use to query the Pricebook object to get the Id for that PFC_Proudct__c.

Opportunity o = [SELECT Id, Campaign.PFC_Product_Name__c FROM Opportunity WHERE Id = '0063B000006bxt6QAA'];
Pricebook2 pb = [SELECT Id, Name FROM Pricebook2 WHERE PFC_Product__c = :o.Campaign.PFC_Product_Name__c];

Any help would be appreciated.

Thanks,
Jonno
 
Amit Chaudhary 8Amit Chaudhary 8
Can you please try like below
Pricebook2 pb = [SELECT Id, Name FROM Pricebook2 WHERE PFC_Product__c in  (SELECT Campaign.PFC_Product_Name__c FROM Opportunity WHERE Id = '0063B000006bxt6QAA' )  ];