Skip to main content
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, 
9 件の回答
0/9000