• David García Gallego
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
Hello guys, 

I have an issue when creating an order, not in opportunity, in 'Order' Object. 
I mean, i have 2 different record types for order and 2 different record types for pricebooks, depending on the record type selected in orders. 
I want to automatically select the pricebook depending on the order record type selected. 

For ex, If I select a 'Pedido de muestras' order type, I want automatically to select 'Pedido estandar' Pricebook later in AddProducts. 

This is the code I'm writing

trigger setPriceBook on Order (before insert) {

ID PRICEBOOK_MUESTRAS = '0124E0000005DyQ';

ID PRICEBOOK_PRODUCTOS_ESTANDAR = '0124E0000005E7I';

ID REC_TYPE_PEDIDO_DE_MUESTRAS = '0124E0000005DyB';

ID REC_TYPE_PEDIDO_ESTANDAR = '0124E0000005Dr5';

for( Order order : trigger.new ) {

if ( order.RecordTypeId == REC_TYPE_PEDIDO_DE_MUESTRAS ) {

order.Pricebook2Id = PRICEBOOK_MUESTRAS;

}

else if ( order.RecordTypeId == REC_TYPE_PEDIDO_ESTANDAR ) {

order.Pricebook2Id = PRICEBOOK_PRODUCTOS_ESTANDAR;

}

}

}


Seems is not working.

Do you have any ideas? Not just about the apex, also about the way to do it. 

Thanks in advance. 

David, 
Hello guys, 

I have an issue when creating an order, not in opportunity, in 'Order' Object. 
I mean, i have 2 different record types for order and 2 different record types for pricebooks, depending on the record type selected in orders. 
I want to automatically select the pricebook depending on the order record type selected. 

For ex, If I select a 'Pedido de muestras' order type, I want automatically to select 'Pedido estandar' Pricebook later in AddProducts. 

This is the code I'm writing

trigger setPriceBook on Order (before insert) {

ID PRICEBOOK_MUESTRAS = '0124E0000005DyQ';

ID PRICEBOOK_PRODUCTOS_ESTANDAR = '0124E0000005E7I';

ID REC_TYPE_PEDIDO_DE_MUESTRAS = '0124E0000005DyB';

ID REC_TYPE_PEDIDO_ESTANDAR = '0124E0000005Dr5';

for( Order order : trigger.new ) {

if ( order.RecordTypeId == REC_TYPE_PEDIDO_DE_MUESTRAS ) {

order.Pricebook2Id = PRICEBOOK_MUESTRAS;

}

else if ( order.RecordTypeId == REC_TYPE_PEDIDO_ESTANDAR ) {

order.Pricebook2Id = PRICEBOOK_PRODUCTOS_ESTANDAR;

}

}

}


Seems is not working.

Do you have any ideas? Not just about the apex, also about the way to do it. 

Thanks in advance. 

David, 

I have activated the opportunity products (and 2 price books) in my sandbox environment and have activated "Prompt users to add products to opportunities"

 

After making a new Opportunity, in step 2 users have to select a pricebook before products can be added to the opportunity.

 

In our situation the two price books (professionals Services and projects) are dependent on the type of Opportunity: (professional Services and project). It would be very user friendly if the price book automaticly would be chosen dependent of the opportunity type that is filled in at the new Opportunity (professional services and projects).

 

At this moment users have to fill in what type of opportunity it is, but again have to select what pricebook belongs to that opportunity type. That's not ideal.

 

Is there a solution to automate this?