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
Steve BerleySteve Berley 

setOrgWideEmailAddressId() giving Invalid ID error

I’m having a problem with setOrgWideEmailAddressId() when sending a single email — anyone else running into troubles?

Even though the OWE email address is verified and I’m using the id retrieved from querying the owe object — it ALWAYS gives an “Invalid Id” error.

What am I doing wrong?
VinayVinay (Salesforce Developers) 
Hi Steve,

Check if"Allow All Profiles to Use this From Address" in Organization-Wide Email Addresses is selected on profile.

Can you check API version of controller if you have any?    

https://help.salesforce.com/articleView?id=emailadmin_orgwide_addresses_considerations.htm&type=5

Set up a dedicated email address by navigating to Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu. Once you have created an org-wide address (note that Salesforce will require you to confirm the address prior to using it, so if you're going to be sending things from a junk address it would be wise to set up a catch-all mailbox so you receive the confirmation email), grab the Id from the URL and use the setOrgWideEmailAddressId(Id) method on your instance of Messaging.SingleEmailMessage.

If you want to avoid hard-coding an Id, after creating your Org-Wide Address you can query them:

OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@blahblah.com'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
if ( owea.size() > 0 ) {
    mail.setOrgWideEmailAddressId(owea.get(0).Id);
    
    }
    
Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
Steve BerleySteve Berley
Thanks for the reply. 1. yes, it’s set to all. 2. The class was created last week and the api version is in the high 40s. 3. Hard coding the id only for debugging this problem. Thx for the tip though. Steve Steve Berley Left Propeller Salesforce Consulting steve@leftpropeller.com 510 459 0558
VinayVinay (Salesforce Developers) 
Change the email address and try to re-verify.

https://help.salesforce.com/articleView?id=000340122&type=1&mode=1

Request you to log a case with salesforce support.

Thanks,
Vinay Kumar