You need to sign in to do that
Don't have an account?
Scott Carlson
Beginning Trigger - Set Opp Pricebook from Account Values
I'm trying to learn about triggers in SF - and am working on my first task: a trigger that will set an Opportunity price book based on two Account field values.
GPO__c is a text field
GPO_Tier__c is a number
I'm trying to set the Opportunity Price Book based on these field values. Example - if the Account GPO is "GPO A" and the GPO Tier is 1, it should match a price book with the name of "GPO A Tier 1".
Here's some code I've put together so far:
GPO__c is a text field
GPO_Tier__c is a number
I'm trying to set the Opportunity Price Book based on these field values. Example - if the Account GPO is "GPO A" and the GPO Tier is 1, it should match a price book with the name of "GPO A Tier 1".
Here's some code I've put together so far:
trigger SetOppPriceBook4 on Opportunity (before insert) { for(Opportunity o : trigger.new){ List<Account> acct = [SELECT GPO__c, GPO_Tier__c, Id FROM Account WHERE ID = :o.AccountId]; List<Pricebook2> pb = [SELECT id from Pricebook2 WHERE Name = :acct[0].GPO__c + ' Tier ' + :acct[0].GPO_Tier__c]; if(!pb.isEmpty()){ o.PriceBook2Id = pb[0].id; } else {o.Pricebook2Id = NULL; } } }I think I'm running into some problems with concatenating within the select statement. What do I need to change
formula field PriceBookAccount = Account.GPO__c + ' ' + Account.GPO_Tier__c
if this helps mark as resolved :)