function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IleneIlene 

Deactivating Users via API

When deactivating user in the salesforce.com user interface you are given three checkboxes:

Remove user from account teams

Remove user from sales teams of closed opps

Remove user from sales teams of open opps. (This one is checked by default).

When deactivating user with the API, do any of the above occur?

DevAngelDevAngel

Hi Ilene,

When you deactivate a user that is part of a sales team, the user is not automatically removed from any opportunities.  The user is automatically removed from the salesteam.  The changes that occur that are related to team selling happen on the UserTeamMember object.  The deactivated user is removed from this table.

You can remove the team member manually after deactivating the user by searching for the records in the OpportunityTeamMember object where the userId matches the id of the user you are deactivating.  You can simulate the option provided in the interface by further restricting the OpportunityTeamMember selection using only opportunity ids of open or closed opportunities.

If you want to remove the user from open and closed opps, just do a search for OpportunityTeamMembers where the user id equals the user id of the deactivated user.

If you want to remove the user only from open opps, do a search for open opps to obtain those ids.  Then do a search for OpportunityTeamMembers where the user id equals the user id of the deactivated user anded with the list of ids from the opp search.

(UserId = {id} and OpportunityId = {oppId_1}) or (UserId = {id} and {OpportunityId = {oppId_2}) or .... (UserId = {id} and {OpportunityId = {oppId_n})

z_harika88z_harika88

Hi Dave,

 

I am deactivating users through apex code and I would like to delete the user automatically from the case team and account team.

If we deactivate user through salesforce UI,then we will get a page which specifies the following:

Remove user from account team.

Remove user from Sales team for open opportunities.

Remove user from Sales team for closed opportunities.

Remove user from Predefined case team.

Remove user from ad hoc case team.

 

please suggest if there are any workarounds to delete the user from team using apex.

 

Thanks,

Harika.

Praveen KimarPraveen Kimar

Hi Harika,

 

I have a suggestion for you, use SOSL query in Apex code to query the OwnerIds from all the dependent objects associated with the user and update them to any other to remove the dependency.

 

hope this will work for you.

 

Regards,

Praveen K. 

Murthy vvrMurthy vvr

Hi Harika,

 

        Did you get any solution to this ?? I'm also trying to inactivate users through apex.

 

Thanks,

Murthy VVR.