通过Apex/记录触发流无法更新ProfileId的问题排查
社区用户Profile切换功能问题排查
需求描述
为社区合作伙伴用户提供通过LWC组件切换页面的功能,需根据用户选择同步更新其Profile(已基于登录用户Profile配置页面变体,且通用对象的页面布局随Profile不同而不同)。
已尝试方案
- LWC调用Apex:因社区用户无Manage User权限且无法授予,失败;
- Future方法:事务独立,无法同步更新并刷新页面,不可行;
- API调用:通过Apex以管理员身份调用API可实现,但受API限额限制。
当前尝试与问题
使用Before Update触发器/记录触发流实现,编写的Apex代码无运行时错误,但未实际更新Profile。代码如下:
public override void onBeforeUpdateFunction(){ // Calling helper method to get a map of "<ProfileName, ProfileId>" Map<String,String> mapPortalNameToProfileId = getProfileId(); for(Sobject obj : Trigger.new){ User newRecord = (User)obj; User oldRecord = (User)Trigger.oldMap.get(obj.Id); if(mapPortalNameToProfileId.containsKey(newRecord.newProfileName__c)){ newRecord.ProfileId = mapPortalNameToProfileId.get(newRecord.PC_DefaultPortal__c); } } }
疑问
为何Profile未更新?Salesforce是否会静默忽略Apex对Profile的更新?
内容的提问来源于stack exchange,提问作者sForSujit
相关产品推荐
相关产品推荐

