You need to sign in to do that
Don't have an account?
Restricting trigger to Record Type!
Hey Guys,
Looking for a way to restrict a trigger when a specific opportunity record type isn't selected.
My Code:
trigger Opportunity on Opportunity (after insert) {
List<OpportunityLineItem> blineItems = new List<OpportunityLineItem>();
for(Opportunity o : trigger.new){
string a;
string b = o.Product2__c;
String c = o.RecordTypeId;
if(c == '012T00000000LSb') {
if(b == 'VOIP') {a = '01uT0000000zxBPIAY';}
else if(b == 'Radio') {a = '01uT0000000zxC9IAI';}
else {a = '01uT0000000zxC2IAI';}
blineItems.add(new OpportunityLineItem(quantity = o.Product_Quantity__c,
UnitPrice = o.Product_Price__c,
OpportunityId = o.Id,
pricebookentryid = a
));
}
}
insert blineItems;}
And maybe there's a more efficient way to use Case for PriceBookEntryId's: VOIP, Radio etc...
Thanks in advance!
I'm not entirely sure if you want the trigger to fire when the RecordTypeId is a specific value or to fire when it is not a specific value. If the check is for when the RecordTypeId is a certain value then your code should work fine. If you're checking when not equal to a certain value use "if (c != '012T00000000LSb') {".
The other thing you may want to verify is that you can perform the comparison with the 15 character version of the Id versus the 18 character version. I usually use the full 18 character Id value when performing comparisons.
-greg
All Answers
I'm not entirely sure if you want the trigger to fire when the RecordTypeId is a specific value or to fire when it is not a specific value. If the check is for when the RecordTypeId is a certain value then your code should work fine. If you're checking when not equal to a certain value use "if (c != '012T00000000LSb') {".
The other thing you may want to verify is that you can perform the comparison with the 15 character version of the Id versus the 18 character version. I usually use the full 18 character Id value when performing comparisons.
-greg