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

get the Org Wide Address ID
Hi,
Is it possible to get the ID of the Organization Wide Address you want, to be chosen with a test on its display address ?
I would like not to put "hard code" ID.
I found some code somewhere and pasted it in mine, but it doesn't work :
// create a new single email message object Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); // Assign the addresses for the To, CC and BCC lists to the mail object. email.setBccAddresses(lEmailAddressesList); // Use Organization Wide Address for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) { if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); } // Specify the subject line for your email address. email.setSubject('The request has been closed : ' + closedRequest.Name); // Set to True if you want to BCC yourself on the email. email.setBccSender(false); // Optionally append the salesforce.com email signature to the email. // The email address of the user executing the Apex Code will be used. email.setUseSignature(false); email.setHtmlBody('This request :<b> ' + closedRequest.Name +' </b>has been closed<br />' + 'Subject : ' + closedRequest.Subject__c +'<br />' + 'Short description : ' + closedRequest.Short_description__c +'<br />' + '<p>Resolution :<b> ' + closedRequest.Answer__c +' </b></p>' + '<p>Thank you</p>'); email.setSaveAsActivity(false); // Send the email you have created. Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email })
For now, I haven' find any documentation about this.
Does someone have any solution for me ?
Marie
You need to pull the displayname field back from the database too:
All Answers
These line are attempting to locate the OWA:
This is looking tor an org wide address where the email contains 'CSR' - is that correct for your instance?
Yes, that's right.
We have 2 Org Wide Addresses, and I want to get the second one.
Its display name is : Keystonefoods CSR Helpdesk-no reply
Thing is, you are comparing the email address and not the display name. Does the email address contain the exact 'CSR' pattern?
You're right, it doesn't....
I'm gonna change my code, and let you know...
Here is my code now :
And her is the message I get when I execute the code :
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger CSR_CORE_RequestAfterUpdate caused an unexpected exception, contact your administrator: CSR_CORE_RequestAfterUpdate: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OrgWideEmailAddress.DisplayName: Class.CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail: line 117, column 6".
You need to pull the displayname field back from the database too:
ooopss...
it's evident !!!
It's working perfectly now !
and sorry, I'm really a novice !!!
thanks, thanks, THANKS !!!!
Marie
Hi
I couldn't send email using OrgWideEmailAddress.Id before verification of this email - it thows exception.
How can I check if Adress from OrgWideEmailAddress oblect was VERIFIED?
thanks
When you initially set up the org-wide email, it sends a verification email to the email address. There is a link in the email sent to the org-wide email address, that once clicked, verifies the address. Then, to double-check, the Admin can login to salesforce.com, and under Setup | Administration Setup | Email Administration | Org Wide Email Addresses, the status will be set to "Verified."
thanks for the advice,
but I'd like to check verification status of selected org-wide email in apex code.
Thank you so much Bob for helping here.