Problem

The healthcare provider onboard their customers to the salesforce experience cloud. They are currently seeking a more integrated and personalized engagement on their portal. To meet this goal, they have identified the need to create an apex method to add users to public groups within the platform.


The company uses public groups to organize their users, particularly for arranging meetings and events in specific geographical locations. When sending invites to these events, users are queried from their respective public groups, ensuring a targeted and location-specific approach.


Complete the given apex code to practice adding a user to a public group.


Instructions:


1. The given apex method accepts two input parameters. The first parameter is the public group developer name and the second one is the target user id


2. Add the user to the public group as a group member to satisfy the business requirement


Example:


//Adding user to public group

userManagementController.addToPublicGroup('SouthWest-Phoenix','0055h00000A9KSF');

//User added as a groupMember to public gropup 'SouthWest-Phoenix'


Note: This exercise is designed to introduce you to writing an apex method to add a user to a public group. Focus on implementing the business requirements and learn more about public groups and group members in salesforce. Feel free to validate your code by clicking the execute button.