You need to sign in to do that
Don't have an account?
Scotty Force
Trigger question regarding RecordTypeName
I've written a basic trigger, which has recordtypeid as hard coded value, need help switching criteria to recordtype.name. So i can clean up the code. Please help. Thanks!!
trigger AccountCurrencyTrigger on Account (before insert,before update)
{
for(account acc:trigger.new)
{
if(acc.Currency_Test__c < 0 && acc.RecordTypeID == '018f4567348MBvb')
{
System.debug('Record Type ID: '+acc.RecordTypeID);
acc.adderror('Sorry, Currency cannot have negative value');
}
}
}
trigger AccountCurrencyTrigger on Account (before insert,before update)
{
for(account acc:trigger.new)
{
if(acc.Currency_Test__c < 0 && acc.RecordTypeID == '018f4567348MBvb')
{
System.debug('Record Type ID: '+acc.RecordTypeID);
acc.adderror('Sorry, Currency cannot have negative value');
}
}
}
In your trigger you can filter on your records by simply Where RecordTypeId = rt.Id;
All Answers
you can get record type id as shown below also
Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Development').getRecordTypeId();
In your trigger you can filter on your records by simply Where RecordTypeId = rt.Id;