You need to sign in to do that
Don't have an account?

need help bulkifying
i have a pricebook setup where price book has a multiselect picklist called Customer_Grouping_Codes
example:
Pricebook1 has Customer_Grouping_Codes: a1,a2,a3,a5,a9,a10
Pricebook2 has Customer_Grouping_Codes: a4,a6,a7,b1,b2
etc....
- on my account object i have a field called Customer_Group_1_Code__c(this is uploaded from source data warehouse)
- account: abc has Customer_Group_1_Code__c = a3
- I now have a field called Default_Price_Book__c on Account that is Lookup(Price Book)
- what i need to do is set this Account.Default_Price_Book__c on before insert, before update to the Pricebook2.id corresponding to Account.Customer_Group_1_Code__c
here is what i have so far:
trigger AccountPriceBookSelector on Account (before insert, before update) { for(Account acc : Trigger.new) { if(acc.Customer_Group_1_Code__c!=null) { List<Pricebook2> pb = [select id, name from PriceBook2 where Customer_Grouping_Codes__c includes (:acc.Customer_Group_1_Code__c) ]; if(!pb.isEmpty()) { acc.Default_Price_Book__c=pb[0].id; } } else { List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; acc.Default_Price_Book__c = stdPBL[0].id; } } }
I'm just not sure where to start with this - it looks so easy (pseudo code) but i'm having trouble
Try with belwo code ,
Let me know if it helps !!
Thanks
Manoj
i tried "...Where Customer_Grouping_codes__c includes (:customerGrpCodeSet)"
but that is giving an error in dev console: Invalid bind expression type of set<string> for column of type string
BUT - it works in the Query Editor when i type it like "...Where Customer_Grouping_Codes__c includes ('A1')