+ Start a Discussion
NaradorNarador 

Can you enable SSO with a Post Copy Apex class?

As part of a citizen development project I'm working on, there is a new to automatically provision sandboxes to non admins giving them sys admin in that environment. I'm looking to create a post copy apex class that can do the following things:
  1. Enable Single Sign On
  2. Enable an Authentication Service in My Domain
  3. Change a user's Profile
  4. Change a user's email without requiring verification from the new address
  5. Send an email to that user
Is this possible, and if so does anyone have any classes I can reuse or tailor to my needs? Thanks!
ShirishaShirisha (Salesforce Developers) 
Hi Narador,

Greetings!

I don't think enabling the SSO is possible by Post Copy Apex class as whenever you create the Sandbox then it will copy the Production data which includes the SSO configuration as well.

Also,whenever you change the email address of an existing user then an email should send to the user for verification unless they unsubscribe to the salesforce emails.

And,yes we should be able to change the profile of the users by querying and updating with the new profiles with apex code.

Please refer the sample code which you can use it in your Post apex class:

https://developer.salesforce.com/forums/?id=9060G000000I6fTQAS

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
NaradorNarador
I have SSO enabled already in production but whenever I refresh, SAML is disabled. I should have been more specific that this is what I wanted to change from False to True. See below:
SAML Enabled checkbox
Then I want to enable an Authentication Service as seen below. When refreshing, the 4th option down is NOT checked. I want to have it checked automatically after refresh:
Authentication Services

When changing an email there is a link sent to the new email address for verification. Is there a way to bypass that for just for sandbox environments?

Changing profile seems quite simple. Thanks for the info! Let me know on the above.