web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard