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
Devendra NataniDevendra Natani 

Unexpected behaviour of trigger on User Object

I have a contact which has a partner user. I am disabling the partner user from contact detail page by selecting "Disable partner user" option from "Work with Portal Button" dropdown.

 

I have a trigger on User object which fires on after update event.

 

trigger TR_User on User (after update) {
system.debug('########'+trigger.new[0].IsActive + '-' + trigger.old[0].IsActive);
}

 

In this trigger I am checking the IsActive field value of user object. But both Trigger.New[0].IsActive and Trigger.Old[0].IsActive returns same value i.e true. While I was expecting it to become false as User is disassociated from the contact in this process.

 

I am not sure whether it is a bug in the Salesforce or I am missing something...

 

Please Suggest.

 

Thanks,

Devendra Natani

Blog

 

 

Best Answer chosen by Admin (Salesforce Developers) 
KyleKyleKyleKyle

The isActive field on the user can take up to 10 seconds to register the change to false when the portal user is deactivated from the contact. The isportalenabled field on the user shows the correct change of state during this event, and can be used as the flag for a trigger.

See:  (after update trigger on user)
10:26:21.168|USER_DEBUG|[6]|DEBUG|
##########Trigger.new: User:{IsPortalEnabled=false, IsActive=true}

##########Trigger.old:User:{ IsPortalEnabled=true, IsActive=true }

All Answers

dotnet developedotnet develope

Hi Friend,

 

I have couple of queries by seeing our post.

 

1) have you tried to login with the disabled user using the portal link (URL)?

2) have you checked isActive checkbox is unchecked?

3) On which criteria are you determining the contact is associated to particular diabled account?

 

Thanks,

:smileyvery-happy:

 

 

 

KyleKyleKyleKyle

The isActive field on the user can take up to 10 seconds to register the change to false when the portal user is deactivated from the contact. The isportalenabled field on the user shows the correct change of state during this event, and can be used as the flag for a trigger.

See:  (after update trigger on user)
10:26:21.168|USER_DEBUG|[6]|DEBUG|
##########Trigger.new: User:{IsPortalEnabled=false, IsActive=true}

##########Trigger.old:User:{ IsPortalEnabled=true, IsActive=true }

This was selected as the best answer
truebrucetruebruce

Thanks KyleKyle,

 

had the same problem and thanks to your suggestion it started working!!

PrajsamPrajsam

Even if you disable the partner contact the user is still active as a non-partner user in salesforce. IsActive flag is related to salesforce user and not its partner contact user.

Santi DiezSanti Diez
Hi, I had the same problem detecting changes on the "IsActive" field on the before update trigger, however, it seems to be perfectly working on the AFTER update trigger.