You need to sign in to do that
Don't have an account?
Associated price book for an opportunity
How to find associated price book for a given opportunity. For example, when I add a product under opportunity for the first time, it asks me to select a price book. Now in my apex code, I need to check whether a given opportunity already has a related price book or not?

SELECT Product2Id FROM OpportunityLineItem WHERE OpportunityId=oppIdFromURL'
SELECT Pricebook2.Name FROM PricebookEntry WHERE Product2Id='ProductIdFromFirstStep'
You can query the Opportunity object and get the PricebookId to find out if existing pricebook is there related to Opportunity.
Pricebook2Id
ID of a related Pricebook2 object. The Pricebook2Id field indicates which Pricebook2 applies to this opportunity. The Pricebook2Id field is defined only for those organizations that have products enabled as a feature. You can specify values for only one field (Pricebook2Id or PricebookId)—not both fields. For this reason, both fields are declared nillable.
http://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_opportunity.htm
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
This gives me complilation error that
Error: Field Opportunity.Pricebook2Id does not exist. Check spelling