[懸而未決] Portal account owner must have a role

症狀

在一個簡單的 Test Class 中,insert 了 test account、test contact,到了要 insert test user  的時候就噴這個 error: 
FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, portal account owner must have a role: []

大致就跟這幾篇描述的一致,
  • https://help.salesforce.com/s/articleView?id=000330124&type=1
  • https://developer.salesforce.com/forums/?id=9060G0000005skdQAA

但是採用了其中的解法,確保 running user has a role 後,仍然沒有任何的改善。
我看起來 account owner 和 contact owner 都有 UserRole,Running User 也有 UserRole。
我也加了這段來檢查,也通過了:
// UNKNOWN_EXCEPTION, portal account owner must have a role: []
System.assertNotEquals(null, UserInfo.getUserRoleId(), 
'The current user with Id: ' + UserInfo.getUserId() + ' Name: ' + UserInfo.getUserName() + ' needs a Role assigned to test Portal/Community users');

但在 insert user 的時候就是會 fail。

暫時繞彎先過了這個 Test Class,日後有機會再來細察。

留言

這個網誌中的熱門文章

ISC2 CC (Certified in Cybersecurity Certification) 考試心得

Salesforce證照考試心得 (Administrator and Advanced Administrator)