取引先責任者をパートナーまたはカスタマーポータルユーザとして有効化しようとすると、「UNKNOWN_EXCEPTION, portal account owner must have a role: []」(不明な例外、ポータル取引先所有者にロールを設定する必要があります: []) というエラーが表示される場合があります。
上記のエラーは、次のコードスニペットで発生する可能性があります。
Account a = new Account(Name='Test Account Name'); insert a; Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id); insert c; User user = new User(); user.ProfileID = [Select Id From Profile Where Name='Some Portal Profile Name'].id; user.EmailEncodingKey = 'ISO-8859-1'; user.LanguageLocaleKey = 'en_US'; user.TimeZoneSidKey = 'America/New_York'; user.LocaleSidKey = 'en_US'; user.FirstName = 'first'; user.LastName = 'last'; user.Username = 'test@uniquedomain.com'; user.CommunityNickname = 'testUser123'; user.Alias = 't1'; user.Email = 'no@email.com'; user.IsActive = true; user.ContactId = c.Id; insert user;
このエラーは、コードを実行しているユーザにロールが設定されていない場合に発生します。
次のコードを実行するユーザに必ずロールを割り当ててください (例: システム管理者ユーザにはデフォルトではロールが割り当てられていません)。エラーを解決するには、ユーザにロールを割り当てます。
同じ理由で、取引先責任者をパートナーあるいはカスタマーポータルユーザとして有効化しようとすると同じエラーが表示されます。
次のサンプルコードで、Test クラスでこのエラーを回避する方法を示します。
UserRole userrole = [Select Id, DeveloperName From UserRole Where DeveloperName = 'CEO' Limit 1];
User adminUser = [Select Id, UserRoleId From User Where Profile.Name='System Administrator' Limit 1];
adminUser.UserRoleId = userRole.Id;
update adminUser;
System.runAs(adminUser){
Account a = new Account(Name='Test Account Name');
insert a;
Contact c = new Contact(LastName = 'Contact Last Name', AccountId = a.id);
insert c;
User user = new User();
user.ProfileID = [Select Id From Profile Where Name='Customer Community User'].id;
user.EmailEncodingKey = 'ISO-8859-1';
user.LanguageLocaleKey = 'en_US';
user.TimeZoneSidKey = 'America/New_York';
user.LocaleSidKey = 'en_US';
user.FirstName = 'first';
user.LastName = 'last';
user.Username = 'test@uniquedomain.com';
user.CommunityNickname = 'testUser123';
user.Alias = 't1';
user.Email = 'no@email.com';
user.IsActive = true;
user.ContactId = c.Id;
insert user;
}
000385901

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.