function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
m-nakanom-nakano 

コミュニティユーザーの一括登録

登録済の取引先責任者をApex処理による自動作成を行いたいです。
取引先責任者のリストビュー内にカスタムボタンを設置し、ボタン押下で
Apex処理が実行されてコミュニティーユーザーに登録されるのが理想だと思っていますが、
Apex処理で実行可能でしょうか??
Taiki YoshikawaTaiki Yoshikawa
試していないのでおそらくなのですが、Apex処理でしたら実行可能のはずです。
以前ポータルユーザだったときはこんな感じでApexから登録できました。
/**
 * ポータルユーザ
 */
public static User createPortalUser(Profile profile, Contact contact, Boolean isInsert) {
    
    User portalUser = new User(
         LastName = 'TestPortalUser'
        ,Alias = 'Portal'
        ,Email = 'portaluser@example.com'
        ,Username = 'portaluser@example.com.dev'
        ,CommunityNickname = 'TestPortalUser'
        ,EmailEncodingKey = 'ISO-2022-JP'
        ,TimeZoneSidKey = 'Asia/Tokyo'
        ,LocaleSidKey = 'ja_JP'
        ,LanguageLocaleKey = 'ja'
        ,ProfileId = profile.Id
        ,ContactId = contact.Id
    );
    
    if (isInsert) {
        insert portalUser;
    }
    
    return portalUser;
}
呼び出し時のイメージです。
/**
 * カスタマーポータル
 */
static testMethod void createPortalUserTest() {

    System.runAs(testAdminUser) {
        Account account = CommonTester.createAccount(true);
        Contact contact = CommonTester.createContact(account, true);
        Profile profaile = CommonDao.getProfile(System.Label.Profile_Portal_User);
        
        Test.startTest();
        
        // Insertなし
        User portalUser = CommonTester.createPortalUser(profaile, contact, false);
        System.assertEquals(String.isEmpty(portalUser.Id), true);
        
        // Insertあり
        portalUser = CommonTester.createPortalUser(profaile, contact, true);
        System.assertEquals(String.isNotEmpty(portalUser.Id), true);
        
        Test.stopTest();
    }
}

上記はテストクラスで使用するためのテストユーザを用意するための処理ですが、同じような感じで値をセットすれば登録処理を実装できると思います。