无法创建门户用户。 REQUIRED_FIELD_MISSING,缺少必填字段:[个人资料]:[个人资料]

问题描述 投票:0回答:2

我正在尝试使用以下代码从社区公共页面创建门户用户:

this.userVar = new User(
                Alias = (this.contactVar.FirstName + this.contactVar.LastName).toLowerCase(),
                Email = this.contactVar.Email,
                FirstName = this.contactVar.FirstName,
                LastName = this.contactVar.LastName,
                EmailEncodingKey = 'UTF-8',
                LanguageLocaleKey = 'en_US',
                LocaleSidKey = 'en_AU',
                Country = 'Australia',
                ProfileId = assistanceHubProfile.Id,
                IsActive = true,
                TimeZoneSidKey = 'Australia/Sydney',
                Username = this.contactVar.Email,
                ContactId = this.contactVar.Id
            );
            System.debug(this.userVar);
            insert this.userVar;

但是我有这个错误:

Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Profile]: [Profile]

插入前系统调试:

User:{Alias=tedsttestte, [email protected], FirstName=Tedst, LastName=Testte, EmailEncodingKey=UTF-8, LanguageLocaleKey=en_US, LocaleSidKey=en_AU, Country=Australia, ProfileId=00e920000002Ag1AAE, IsActive=true, TimeZoneSidKey=Australia/Sydney, [email protected], ContactId=00392000003RLeXAAW}

如您所见,ProfileId 已填充。我不明白为什么会发生这个错误。

User SObject 没有触发器和触发流程

salesforce apex
2个回答
0
投票

这是因为我在顶点类定义中没有使用

without sharing
关键字。在我的例子中,apex 类默认使用
with sharing
设置。


0
投票

丹尼尔解决方案对我有用,谢谢!

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.