+ Start a Discussion
S91084S91084 

Create a Public Group Membership by Custom Portal User

Hi ,

 

I am trying to create a public group membership through Apex from the cutomer portal. When I login to the portal as an admin and run the Apex Code, it is adding me to the public group. If I login to the portal with Salesforce cutomer portal ser, it is not working as expected. I know this is because only admin can creat/edit public groups and its members. But is there way that while creating the group through Apex, I can run that peice of code in the context of System Administrator?

 

Any Help?

 

Thanks in Advance.

PrakashbPrakashb

In your class are you using  'with sharing' definition. If you are using it then the Customer portal user will not be able to add memebers to public group.

 

 

But if you remove that fro your class definition then your code runs as a System Admin and you will be able to add members to your group.

 

Though removing with sharing from class definition is not advisable as each code needs to run based on the user permission, If you want to achieve your functionality then you can try this solution.

 

Hope it resolves your question. 

 

 

 

 

 

S91084S91084

Hi Prakash,

 

User with "Manage Users" permission can only add memebers to public groups. Portal user do not have the permission to add members to the public group. I cannot use System.runAs() as it can be used only in Test Classes.

 

Is there any other way i can use to perform this operation as an admin in apex class. I could do this in Javascript but would like to do it in Apex.