web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Code Review - Performa...
Power Apps
Unanswered

Code Review - Performance Impact - Assign security roles to users in bulk

(0) ShareShare
ReportReport
Posted on by 971

Hello Experts,

 

I use below code to assign security role to a single user.

 

public static void AssignSecurityRole(Guid guidSystemUserId, Guid guidSecurityRoleId, IOrganizationService crmService)
 {
 
 // Create new Associate Request object for creating a N:N relationsip between User and Security
 AssociateRequest objAssociateRequest = new AssociateRequest();
 // Create related entity reference object for associating relationship
 // In this case we SystemUser entity reference 
 objAssociateRequest.RelatedEntities = new EntityReferenceCollection();
 objAssociateRequest.RelatedEntities.Add(new EntityReference("systemuser", guidSystemUserId));
 // Create new Relationship object for System User & Security Role entity schema and assigning it 
 // to request relationship property
 objAssociateRequest.Relationship = new Relationship("systemuserroles_association");
 // Create target entity reference object for associating relationship
 objAssociateRequest.Target = new EntityReference("role", guidSecurityRoleId);
 // Passing AssosiateRequest object to Crm Service Execute method for assigning Security Role to User
 crmService.Execute(objAssociateRequest);
 }

 

 

I am executing above code from my console utility. I see performance degrade when I need to assign multiple security roles to 10k users.

 

Need you help and guidance to improve my performance of the code.

 

Thanks,

Bipin

 

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard