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
CaitlinGMCaitlinGM 

Sending mass email to group of contacts

I need to isolate a group of contacts and send them an email. Essentially, I need a SOQL statement along the lines of: select email from Contact
where ID in (select instructor_name__c.id from Opportunity where stage='Active' and Location__c='Arlington')

Or something to that effect. Then, I would create a list and send an email to that group. Could I accomplish this with an Apex class and a javascript button? Or does it have to be a Visualforce button? Is there a better way (maybe this is something Conga Composer can do?) I just want to make sure I'm on the right track.

Relatedly, what if I just want to generate a report of all contacts meeting the criteria of my SOQL statement? Is there some way to just display the list? Thanks.
sfdcfoxsfdcfox

You can do it any way you'd like to. All of the options you listed are viable.

 

You could use Apex Code, called from JavaScript. You can do this by creating a webservice or REST endpoint, or by calling it using the JavaScript files "/soap/ajax/22.0/connection.js" and "/soap/ajax/22.0/apex.js"  (using sforce.apex.execute). You'd want to use REQUIRESCRIPT using that method. You could even use this button from a list view.

 

You could create a Visualforce page, backed with a custom controller, if you'd like to present a nice user interface. You could use your SOQL statement this way.

 

I'm assuming Instructor_Name__c is a contact? Since you can't mass email custom opportunity fields, those options are probably your best choices. If you wanted to create a report with that critera, you could build the report using that criteria directly, then export it or do whatever else you'd like.

cherrysbluecherrysblue

I am a rookie at apex code . Could you provide more information about  the code or other method ?