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
Ashmi PatelAshmi Patel 

Field is not writeable...what can i do with this error

this is my code.....


trigger FixCreator on Case (before insert) {
for (Case newCase : Trigger.new) {
if (newCase.SuppliedEmail != null) {
User trueCreator = [SELECT Id FROM User WHERE Email = :newCase.SuppliedEmail ORDER BY LastLoginDate DESC LIMIT 1];
newCase.CreatedById = trueCreator.Id; } } }




NEED HELP
sfdcMonkey.comsfdcMonkey.com
hi Ashmi Patel
CreatedByID, CreatedDate etc. are known as the Audit Field which you can not update, insert using DML in APEX. You need to contact salesforce support for enabling Audit Fields. Audit Fields are generally used while migrating history data from third party system to salesforce with legacy dates.
Thanks
i hop it helps you
Ashmi PatelAshmi Patel
T
hnkuuu very much......
sfdcMonkey.comsfdcMonkey.com
if it helps you mark it best answerso it make proper solution for  others
:)
sridharbsridharb
Ashmi Patel,

Things changed. You doesnt need to contact Salesforce support any more. Just check following administrative setting from User Interface Settings

"Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions"

Once you enable this, create a permission to allow edit audit fileds and assign that permission set as you required.

Thanks & Regards
Sri