I have a page within my community where a Customer Community user can update some information about themselves (information is saved on Account). I want to create a Task alerting the user that owns the account that information has been changed. Initially i had no issues. I (system admin) profile was the owner of the account I used for testing and tasks were created without problem. However with some further testing in which some other users in the system were the Account owners i received this error.
Initial thought was that the Account owner user was missing some permissions but i am at a loss to which permissions. They own the Account record (Account is also Public Read/Write). The Account owner profile has Access Activities and Edit Tasks permission.
The Customer Community profile has the Access Activities permission but Edit tasks is not in System Permissions. So possibly they can not create tasks but why can they create tasks for a system admin user without issue? They also have no problem updating fields on the account.
Here is my Apex Code, the outer class is with sharing
@AuraEnabled
public static Task sendTask(Id acctId, Id acctOwnerId, String changeReference) {
Task tsk = new Task();
tsk.Subject = 'Profile Has Been Updated';
tsk.Status = 'Open';
tsk.Priority = 'Normal';
tsk.WhatId = acctId;
tsk.OwnerId = acctOwnerId;
tsk.Description = changeReference;
try {
insert tsk;
return tsk;
}
catch (Exception e) {
// "Convert" the exception into an AuraHandledException
throw new AuraHandledException(e.getMessage());
}
}