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
SunilKumar.ax1648SunilKumar.ax1648 

How to save sales force contact in Mail chimp any way to do this

Hi All,

 

I want to save salesforce contact in mailchimp. i am able to save mailchimp object in salesforce but i am not getting any way to save salesforce contact to mailchimp if any body have any idea so plaese share with me. it's very urgent for me thanks in advance if any helf form your side. here i am waiting for yuor valuable response.

Best Answer chosen by Admin (Salesforce Developers) 
SunilKumar.ax1648SunilKumar.ax1648

trigger SubscribeTrigger on Contact (after insert) {
for(Contact c : Trigger.new)
{
if(c!=null)
{

SalesforceWithMailchimpController.subScribe(c.email);
SalesforceWithMailchimpController.findAllListByFolderName('xyz');

}
}
}

All Answers

SunilKumar.ax1648SunilKumar.ax1648

Hi All,

 

I have done,

 

below is step how to save subscribed salesforce contact to Malchimp.

SalesforceWithMailchimpController

 

@future (callout=true)
    public static void subScribe(String emailId)
    {
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setbody('{"apikey": "THIS IS MAIL CHIMP API ID come from mail chimp api -us7","id": "THIS IS LIST ID COME FROM MAILCHIMP LIST ","email": {"email": "'+emailId+'","euid": "1","leid": "49"},"merge_vars": {"new-email": "example new-email","groupings": [{"id": 42,"name": "example name","groups": ["..."]}],"optin_ip": "example optin_ip","optin_time": "example optin_time","mc_location": {"latitude": "example latitude","longitude": "example longitude","anything": "example anything"},"mc_language": "example mc_language","mc_notes": [{"note": "example note","id": 42,"action": "example action"}]},"email_type": "example email_type","double_optin": false,"update_existing": true,"replace_interests": true,"send_welcome": false}');
       
        req.setEndpoint('https://us7.api.mailchimp.com/2.0/lists/subscribe.JSON');
        HttpResponse res = h.send(req);
        system.debug(':: Response :: ********'+res.getbody());
    }

 

SunilKumar.ax1648SunilKumar.ax1648

trigger SubscribeTrigger on Contact (after insert) {
for(Contact c : Trigger.new)
{
if(c!=null)
{

SalesforceWithMailchimpController.subScribe(c.email);
SalesforceWithMailchimpController.findAllListByFolderName('xyz');

}
}
}

This was selected as the best answer