You need to sign in to do that
Don't have an account?

Help! - Trigger for Portal Deactivation based on Field Update!
So I have tried and tried...everything from the process builder to being on the phone with SF support. Nothing has worked, but yet I need to figure something out.
I want to set up a trigger that does the following:
On an Account, say Company XYZ, we have a field called Type. If we set that to Ex-Customer I would like to have every contact that has portal access under that Account to have their portal access deactivated or in general their SF profile frozen/deactivated. Whatever functionality is easier, it doesnt matter to me. I cannot seem to make this happen! This would help us immensely!
This is the trigger I have so far...
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; usersToUpdate.add(u); } }
Please let me know what else I need to add in order to make the Ex-Customer connection and the deactivation of the user/profile/portal.
Thank you
I want to set up a trigger that does the following:
On an Account, say Company XYZ, we have a field called Type. If we set that to Ex-Customer I would like to have every contact that has portal access under that Account to have their portal access deactivated or in general their SF profile frozen/deactivated. Whatever functionality is easier, it doesnt matter to me. I cannot seem to make this happen! This would help us immensely!
This is the trigger I have so far...
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; usersToUpdate.add(u); } }
Please let me know what else I need to add in order to make the Ex-Customer connection and the deactivation of the user/profile/portal.
Thank you
Apex Class
Apex Trigger
All Answers
Something like this might work
Using the process builder, I get a lot of error emails and also the deactivation simply does not happen.
Does the trigger that you posted account for changing the Account Type that the User/Contact belongs to, to Ex-Customer?
Error: Compile Error: unexpected token: List at line 1 column 0
Error:Apex trigger ExCustomers caused an unexpected exception, contact your administrator: ExCustomers: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00521000000Zgg0AAC; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Account: []: ()
Which I have never seen before.
Apex Class
Apex Trigger
So I wouldnt create this from Settings - Customize - Account - Trigger....this would be from the Developer Console and I would need to create an Apex Class and an Apex Trigger from the console right?
For the Apex Class, you can just go to Develop - Apex Classes - New
Error: Compile Error: Variable does not exist: AccountUpdater at line 19 column 9
Update it with this
Ive attached a screenshot of what I have.
This is what I get now when I tried the trigger in the Account object, with the Class already created...
How would I write the test class for this thing so i can push it out to production??!
I got 100% coverage.
When i tried to deploy this in production through change sets, it got the following error (attached).
I pushed over both the Apex Class with the test and the Apex Trigger.
public class AccountUpdaterTest {
@isTest(SeeAllData=true)
static void testExCustomer() {
List< Account > a = [SELECT Id FROM Account WHERE Type != 'Ex-Customer' LIMIT 1];
if( !a.isEmpty() ) {
a[0].Type = 'Ex-Customer';
update a;
}
}
}
This is what i pasted for the Apex Class test class in the developer console
Ive attached an image
Apex Classes:
AccountUpdater
AccountUpdaterTest
Apex Triggers:
ExCustomer
I dont know why. The error is very long.... I've attached a screenshot...so close!!!
I thoroughly appreciate your help