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
naga kiran 2naga kiran 2 

Hi i have requirement of deactivation of portal users after 30 days can we achieve it using time workflow rule instead of apex job?

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Naga Kiran,
To  De-activate Portal User in Apex Code.The below code snippet might help.
// Assume cIds is a list of Contacts whose users we wish to deactivate
List<User> usersToUpdate = new List<User>();
for(User u : [Select u.Id, u.IsActive, u.IsPortalEnabled from User u where u.ContactId    in :cIds]){
    if(u.IsActive || u.IsPortalEnabled ){
        u.IsActive = false;
        u.IsPortalEnabled = false;

if (usersToUpdate.size()>0){
    update usersToUpdate;
Please refer the below link for reference. Hope it will be helpful.

Please mark it as best answer if the information is informative.

Rahul Kumar