3

That's a tricky question. I do not want to send a Fax to Salesforce to deactivate email confirmation because i am afraid of faxes I'm quite in a hurry, and I don't want to do it by hand for 500 users. Their emails were badly set at the beginning, so now that I need to reset their passwords, I am looking for a workaround.

Could it be:

  • Simulating 500 forms POST requests, one for each user ?
  • Using SOAP API ?
  • Rendering the 500 actual forms and doing by hand and some console javascript ?
  • Being a wizard ?

Since the actual email adress is not valid, I can not send a new password before the valid email is confirmed by the user.

And since it is based on a User which has no Contact, SingleEmailMessage will refuse to be sent without a valid WhatId ( pretexting "lies" BTW Salesforce board discussion )

edit: Users cannot be deactivated because we do not want to reset their access to records, because the org is a refresh from prod which is running since 2009. Tricky I said.

  • 1
    I cannot FIND this, but I specifically remember another Question dealing with this, and the Answer was to do something like doing both at the same time? Urgh. Looking again to see if I can find it. It was GUI based, no Apex/etc needed....... – AMM Mar 21 '13 at 17:51
  • Well, in hindsight, you want to do it mass due to your quantity anyway. Oh well. Sorry. – AMM Mar 21 '13 at 17:55
6

You could perform something like this in Execute Anonymous, silently changing their email after deactivating the user and then resetting the password:

// retrieve your 500 users
List<User> users = [SELECT Id, IsActive, Email FROM User WHERE FirstName = 'Derpy'];

// deactivate the users
for (User u : users) {
    u.IsActive = false;
}
update users;

// correct their email addresses
for (User u : users) {
    u.Email += '.nonsense';
}
update users;

// reactivate the users
for (User u : users) {
    u.IsActive = true;
}
update users;

// fire a password reset and send the reset email
for (User u : users) {
    System.resetPassword(u.id, true);
}

Prior to running this script, consider the repercussions of deactivating active users. SFDC Link: Tips on Deactivating Users

  • This is a good option but it won't work if the users are configured in workflows, assignment rules, etc. – PepeFloyd Mar 21 '13 at 22:09
  • Considering that these users don't have valid email addresses in the system, I suspect that they aren't involved in much of that activity. It's a good point to address though. Modified my answer with a link to more information on disabling users. – Mark Pond Mar 21 '13 at 22:41
  • This is a very nice workaround, but in my case the sandbox is a refresh from prod which is running since 2009. I edited the question with this. – Martin Mar 22 '13 at 7:53
  • 1
    Has anyone tried this recently? I'm not seeing this work, I ran a very similar script, and it's still sending the confirmation email for the change. – Matthew Lamb Dec 2 '14 at 22:59
  • Actually manually deactivated a user, saved, then updated their email and saved again, and even that is still sending the email confirmation. – Matthew Lamb Dec 3 '14 at 0:07
2

I have faced this issue at a client implementation - the problem was that when they created sandboxes the user.senderEmail was still set to the public email address for the organisation (all the same address). So in the sandbox they wanted this changed to a temp gmail senderEmail. The issue is how to mass change (in my case about 500 users). We achieved this by:

  1. Setup a temp gmail account, and setup email to case to this address (using gmail to forward to the salesforce mail address)
  2. Execute an anonymous Apex script which gets all the users that are isActive=true and the senderEmail is the public email address (that you want to change), then changes the address to the temp email you've just created in gmail
  3. this will forward an email to gmail - then on to creating a case
  4. Next create a report which gets the body of the email (which contains the URL for the user to click on to confirm the email address change)
  5. get the export of the report into an excel/google sheet and use some functions to isolate the URL from the body of the email.
  6. (Here's the MacGyver bit!!) - encapsulate the URL you've extracted from the excel/google sheet into an HTML image anchor
  7. open the html file you've just created - it will attempt to open the image anchors - and by doing so fire the URL that accepts the email change

I know this is a long winded approach - but it's the only thing I've found to work to automate changing the senderEmail address en masse.

If anyone is interesting in the Apex code, report, sheet functions, and HTML - let me know and I can share it here.

  • I like your style, Sir ! – Martin May 9 '15 at 18:40
  • It's not pretty - and takes more time than is reasonable - but it works for us! – Tammer Salem May 11 '15 at 7:47
0

Found a way, using anonymous execution. A terrible way...:

for each user in my list:
    generate a new password silently
    generate en email with a direct ( unsecure ) login link,
    and the injonction to change their email with another link
    send email to the user
...
profit.

Since the original email address is not valid, they will never be aware that their password has been reset, hence the generated mail with credentials. On first login, because of the reset, the user will be asked to enter a new password. Then he must voluntarily change his email address, following IT group security/management mesures -or claimed as so in the email template.

It is highly insecure of course, so we will not do this. And all of this must respect the send mail governor limits.

For conclusion, i'd say that since it's a salesforce restricted system feature, we can consider that it is securely locked and there is no way around.

I'll get a fax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.