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
ajay kumar 390ajay kumar 390 

I want to create user from apex to access community list

I have three community 
1) a
2) b
3) c

I want to create user from apex that have either access community a or b or c or a,b or a,b,c 
mean base on selection to create user.


User-added imagePlease see atchment .

Thanks

ajay
Naveen Rahul 26Naveen Rahul 26
Hi Ajay,

Try create Seperate Profiles for each Community like below, that is the easiest way.

1) a Community Profile
2) b Community Profile
3) c Community Profile

Assign Users accordningly by Apex like below
 
User u = new user();
u.LastName = 'Test Code';
u.Email = 'test@test.com';
u.Alias = 'Tcode';
u.Username = 'test1234444@test.com';
u.CommunityNickname = 'test12';
u.LocaleSidKey = 'en_US';
u.TimeZoneSidKey = 'GMT';
u.ProfileID = Community Profile ID;
u.LanguageLocaleKey = 'en_US';
u.EmailEncodingKey = 'UTF-8';
insert u;

will this is helpful ??

Thanks
D Naveen Rahul.
ajay kumar 390ajay kumar 390
you all have no knowledge .
Actully this is done by permission set