4

Is it possible to set default pricebook based on recordtypes. We have recordtypes like sales and sevice. So when an user selects sales recordtype we should have sales pricebook as default and service pricebook as default if he selects service recordtype.

Is this possible?

Cheers

2
  • 1
    With an Apex trigger you would be able to do this. Is that an option? – rael_kid Feb 1 '13 at 7:37
  • 1
    Cant it be done through UI? If it cant then i am trigger happy :) – Prady Feb 1 '13 at 8:25
6

Selected Pricebook is stored in Opportunity.Pricebook2Id.

I've quickly hacked a test and it works in my Dev. Edition so yo should be able to write a before insert, before update trigger?

List<Opportunity> opps = [SELECT Id, Name FROM Opportunity WHERE Id = '0067000000U5Wtc'];
opps[0].Pricebook2Id = '01s700000006j5TAAQ';
update opps;

The field is not listed in the setup but you can cheat by hand-crafting the url to it ;) No way to set lookup filters (hmm, maybe from Eclipse) but a validation rule - why not ;)

/p/setup/field/StandardFieldAttributes/d?id=Pricebook2&type=Opportunity

Last but not least - have you seen http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_products.htm?

enter image description here

2
  • Thanks @eyescream, just wanted to confirm that we cant say from UI that this recordtype should use only this pricebook? write trigger to update the pricebookid and to validate that users dont choose any other pricebook we write a validation rule. am i correct in my understanding – Prady Feb 1 '13 at 8:33
  • 1
    Something like that (I might have to do similar thing soon). Field can't be added to Opp page layout (maybe a formula would work if you want to display it?) and since it's technically data and not config thing - it's not selectable in record types config. – eyescream Feb 1 '13 at 9:09
3

Feels weird to answer a 2 year old question that already has a great answer, but since my search took me here, I figure others might see this too:

This is also now possible with Process Builder, for anyone who shies away from Apex. In my use case, I wanted to set a price book upon opportunity creation, but still allow users to have access to the other price books. Since I was also looking to add a base "package" of products to every opp, process builder was my first thought over Apex. Works well -- I may flip it to a trigger eventually so I can do some more advanced manipulation of revenue schedules, but for now, this got the job done! Definitely bookmarking eyescream's answer as well, though!

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.