• ARE you
  • NEWBIE
  • 0 Points
  • Member since 2018
  • Senior Salesforce Architect
  • youperience GmbH

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi, 
I'm facing the following Issue: I need to deactivate portal Users in a Apex class programmatically. 
I already read: https://developer.salesforce.com/forums/?id=9060G000000UUQyQAO, but it is still not working. Here is my code:
 
User user = [SELECT Id FROM User WHERE Contact.AccountId = :accountId];
// fetch Users Id
 Id uid = user.Id;
user.IsActive = false;
user.IsPortalEnabled = false;
System.debug('IsPortalEnabled before saving: ' + user.IsPortalEnabled);
System.debug('IsActive before saving: ' + user.IsActive);
update user;
// re-fetch User Object
User us = [SELECT Name, IsPortalEnabled, IsActive FROM USER WHERE Id = :user.Id];
System.debug('IsPortalEnabled after saving: ' + us.IsPortalEnabled);
System.debug('IsActive after saving:' + us.IsActive);

Even by setting IsPortalEnabled to false before saving if I re-query the same User Object the Flag will be reset. The change of IsActive is stored as expected.

Here is the log output of my Test-Class:

console log

Anybody an Idea why my code is not working?

Thanks in advance
  • September 04, 2018
  • Like
  • 0
Hi, 
I'm facing the following Issue: I need to deactivate portal Users in a Apex class programmatically. 
I already read: https://developer.salesforce.com/forums/?id=9060G000000UUQyQAO, but it is still not working. Here is my code:
 
User user = [SELECT Id FROM User WHERE Contact.AccountId = :accountId];
// fetch Users Id
 Id uid = user.Id;
user.IsActive = false;
user.IsPortalEnabled = false;
System.debug('IsPortalEnabled before saving: ' + user.IsPortalEnabled);
System.debug('IsActive before saving: ' + user.IsActive);
update user;
// re-fetch User Object
User us = [SELECT Name, IsPortalEnabled, IsActive FROM USER WHERE Id = :user.Id];
System.debug('IsPortalEnabled after saving: ' + us.IsPortalEnabled);
System.debug('IsActive after saving:' + us.IsActive);

Even by setting IsPortalEnabled to false before saving if I re-query the same User Object the Flag will be reset. The change of IsActive is stored as expected.

Here is the log output of my Test-Class:

console log

Anybody an Idea why my code is not working?

Thanks in advance
  • September 04, 2018
  • Like
  • 0
HI,

I need to do activate or deactivate portal community users based on contact record checkbox field.

if the check is ture then that contact can be have access on portal community or else can't become a portal user

kindly share your thoughts nd way of approch 

thanks