Very new to Salesforce but not new to SQL guy here. I'm just wondering what method I could use to create a button in a custom object that would query a junction object for the other related object's email fields, then format them into a nice text list.

My schema is like this http://puu.sh/sNqAN/7240986c30.png. I want to be able to hit a button called "Make email list" or something in the tab of any given Interest Group, and be able to have that instance query all its junction objects for the emails in their contact fields, then return the result and do something with it. My general need is to either create a mailing list that can be fed into MailChimp (the current mailing software that the nonprofit I'm working for are using) or otherwise produce a result that the staff could use to help organize their mass emails. The company does have MailChimp integrated into Salesforce at least partially, so if there's a way to just go directly from "Button Press -> (bunch of scripting and queries) -> Mailchimp List" that would be absolutely fantastic.

Any help would be great, and thanks in advace.

  • 2
    You have two options -- let the server do the work and integrate Mailchimp from the controller - or let Javascript do the work by making queries on database and taking results and integrating with Mailchimp. You'll need to expose more about how you plan on passing lists to Mailchimp given Mailchimps APIs
    – cropredy
    Dec 12, 2016 at 23:51
  • I honestly have no idea how their API works or anything, I've just been dumped into this and am trying my best to figure out how to do what they want without making the system overly complex. After further examination it seems like I can probably just use a custom field in Contacts to enable MC to create these lists, but since it's not fully set up and I can't really proceed without consulting the company I guess I'm locked up a bit. Dec 14, 2016 at 21:12

1 Answer 1


I have used visual workflow to output a list of e-mails

Lookup the matching records, and add to sObject collection.

Loop through the collection, and add the value of the current record to a text variable and then add a br()

Then display the text variable in a screen element.

Should work for list up to ~1000 records, depending on how you build it.

I have not worked closely w the mail chimp connector but I believe it works off campaigns so if you are working with standard contacts and leads as your subscribers, it might be easier to use reports to add the correct records to campaigns.

  • I just tried this and for some reason SF doesn't want me to be able to use Contact__c.Email as a field of Interest__c ? Maybe I'm just being dense here, but is there a way I can just use raw SOQL in the Flow Designer? Dec 14, 2016 at 21:40
  • What is interest__c? No you can't use soql in flows, have to suffer through the 1998 flash player magic
    – gorav
    Dec 14, 2016 at 21:47
  • Just put a bullet in me, I don't want to suffer anymore. EDIT: Also whoops no multilines. I want to do something like "SELECT Interests__c.Contact__c.Email from Interests__c WHERE Interests__c.InterestGroup__c.Name == {an input}" (I assume it would look like this) but you'd think I was trying to make a square circle or something. It would be a lot easier if I could just manually join everything. Dec 14, 2016 at 21:54
  • Oh, also it seems I forgot, the objects I'm working with are Contacts, InterestGroup__c and Interest__c (a junction), and Interest__c is a child in a M-D relationship of both of the others. It's in the image I linked. Dec 14, 2016 at 22:02
  • You can do cross object field reference in flow, so if you did a fast lookup on a interest object, and included the contact__c relationship in the sObject variable/collection, you can traverse to pull in the contact email. You might run into issues because you cant filter a query based on a list of IDs, ie lookup list of interest groups where name = x, and then lookup the interest__c records (to get contact email) for those interest groups.
    – gorav
    Dec 14, 2016 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .