function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jezza83Jezza83 

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

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

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

JimRaeJimRae

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.'); } }

 

 

This was selected as the best answer
Jezza83Jezza83
Thanks JimRae.... had a total brain melt on this trigger :) Appreciate your help