You need to sign in to do that
Don't have an account?
Quick Trigger Query
I am trying to prevent all Users (bar Admin Profile) from creating Accounts except for record type x.
I have created a basic trigger below but am receving the error line 5: Comparison arguments must be compatible types: Schema.SObjectField, String - however I thought the below was represented as a string (in single quotes) ?
trigger NonAlignedPractice on Account (before insert) { for (Account TempAccount: System.Trigger.old) { if (Account.RecordTypeId != '01230000000LDuaAAG' && User.ProfileId != '00e300000018UCHAA2') TempAccount.addError('You can only create a Non-Aligned Practice.'); } }
Thanks for any help
You didn't use the name of your looping variable in your if clause.
trigger NonAlignedPractice on Account (before insert) { for (Account TempAccount: System.Trigger.old) { if (TempAccount.RecordTypeId != '01230000000LDuaAAG' && User.ProfileId != '00e300000018UCHAA2') TempAccount.addError('You can only create a Non-Aligned Practice.'); } }
All Answers
You didn't use the name of your looping variable in your if clause.
trigger NonAlignedPractice on Account (before insert) { for (Account TempAccount: System.Trigger.old) { if (TempAccount.RecordTypeId != '01230000000LDuaAAG' && User.ProfileId != '00e300000018UCHAA2') TempAccount.addError('You can only create a Non-Aligned Practice.'); } }