9 Replies Latest reply on Oct 19, 2018 6:00 PM by Sanford Whiteman

    Send Marketo Email button and SFDC Lightning

    Petyr Campos

      Marketo's "Send Marketo Email" button with the Marketo Sales Insight package is not supported by SFDC Lightning because they are javascript based. This means the buttons will not appear when using the Lighting UI in SFDC. Does anyone know of a work around until Marketo addresses this issue?  I know our users can change their UI back to the SFDC classic UI and use the buttons, but that's not the ideal situation. Our users would prefer to say within one UI.

       

      thanks in advance.

      p

        • Re: Send Marketo Email button and SFDC Lightning
          Grégoire Michel

          Hi Petyr,

           

          Are you sure you have upgraded to the lastest version of MSI?

           

          On my instance, it works well:

           

          My MSI version number is 1.4359.2

           

          -Greg

          • Re: Send Marketo Email button and SFDC Lightning
            Danielle Wright

            In case anyone else stumbles across this, here's my solution:

             

             

            Build a visualforce page with this code for contacts:

            <apex:page standardController="Contact" recordSetVar="AllContacts">
            <apex:includeScript value="/soap/ajax/30.0/connection.js"/>
            <apex:includeScript value="/soap/ajax/30.0/apex.js"/>
            <script>
            sforce.connection.sessionId = "{!$Api.Session_ID}";
            var idArr = [];
            list = "{!Selected}"
            list = list.replace("[","").replace("]","")
            idArr = list.split(", ");
            if (idArr[0] == null){
              alert('Please select at least one row');
            }
            else {
              var value = new Array();
              value[0] = new String(idArr);
              var mname = new Array();
              mname[0] = "contactIds";
              var key =
                sforce.apex.execute(
                    "mkto_si.LongGetMethodArguHandler",
                    "putArgus",
                    {
                        name : mname,
                        value : value,
                        contactType : "Contact"
                    }
                );
            try {
            var key = sforce.apex.execute("mkto_si.LongGetMethodArguHandler", "putArgus", { name:mname, value:value, contactType:"Contact" });
            window.top.location = "/apex/mkto_si__Send_Marketo_Email?contactType=Contact&key=" + key +"&retUrl=" + encodeURIComponent(document.location.href); 
            }
            catch(err) {
            window.top.location = "/apex/mkto_si__Send_Marketo_Email?contactType=Contact&contactIds=" + idArr +"&retUrl=" + encodeURIComponent(document.location.href);
            }
            }
            </script>
            </apex:page>
            

            Or this code for leads:

            <apex:page standardController="Lead" recordSetVar="AllLeads">
            <apex:includeScript value="/soap/ajax/30.0/connection.js"/>
            <apex:includeScript value="/soap/ajax/30.0/apex.js"/>
            <script>
            sforce.connection.sessionId = "{!$Api.Session_ID}";
            var idArr = [];
            list = "{!Selected}"
            list = list.replace("[","").replace("]","")
            idArr = list.split(", ");
            if (idArr[0] == null){
              alert('Please select at least one row');
            }
            else {
              var value = new Array();
              value[0] = new String(idArr);
              var mname = new Array();
              mname[0] = "contactIds";
              var key =
              sforce.apex.execute(
              "mkto_si.LongGetMethodArguHandler",
              "putArgus",
              {
              name : mname,
              value : value,
              contactType : "Lead"
              }
              );
            try {
            var key = sforce.apex.execute("mkto_si.LongGetMethodArguHandler", "putArgus", { name:mname, value:value, contactType:"Lead" });
            window.top.location = "/apex/mkto_si__Send_Marketo_Email?contactType=Lead&key=" + key +"&retUrl=" + encodeURIComponent(document.location.href); 
            }
            catch(err) {
            window.top.location = "/apex/mkto_si__Send_Marketo_Email?contactType=Lead&contactIds=" + idArr +"&retUrl=" + encodeURIComponent(document.location.href);
            }
            }
            </script>
            </apex:page>
            

            Then create a new list view button with your visualforce page as the content source:

            Then add the new button to the list view.

             

            It takes a second to load, same as the classic button, but because you're sitting on the visualforce page instead of the list, I also added a "One moment please...." message to the page to pacify impatient users.

            Hope that helps someone in the future.

              • Re: Send Marketo Email button and SFDC Lightning
                Sanford Whiteman

                Better to highlight your code so it's readable using the Advanced Editor's syntax highlighter. (And thanks for the contribution.)

                 

                https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

                  • Re: Send Marketo Email button and SFDC Lightning
                    Danielle Wright

                    I updated to make it formal and readable.

                      • Re: Send Marketo Email button and SFDC Lightning
                        Sanford Whiteman

                        Thanks! Much better.

                         

                        I do see an unreachable condition in your code.

                         

                        When you split() a String, even an empty String, on a non-empty delimiter, it's not possible for the first item in the resulting array to ever loose-equal (nor strict-equal) null.

                         

                        That is, list is always a String here to start:

                         

                        var idArr = [];  
                        list = "{!Selected}";
                        list = list.replace("[","").replace("]","")  
                        idArr = list.split(", ");
                        

                         

                        (You probably meant var list = "{!Selected}" but that doesn't change the outcome.)

                         

                        And even if list is an empty String to start, after the split idArr will be

                         

                         

                          [""]

                         

                         

                        and thus idArr[0] is

                         

                         

                          ""

                         

                         

                        which does not equal null, so this condition will never be met:

                         

                        if (idArr[0] == null){  
                          alert('Please select at least one row');  
                        } 
                        

                         

                        It seems like you're trying to catch when the original String list was empty, for which it's better to force idArr to be an empty Array -- rather than an Array with 1 element that's an empty String.

                         

                        You can do that like so (w/a little other refactoring as well):

                         

                        var list = "{!Selected}",
                            idArr = list.split(/^\[|, |\]$/).filter(Boolean);
                        
                        if (!idArr.length) {
                          alert("Please select at least one row");
                        }
                        

                         

                        Now if list starts out empty, the resulting idArr is an empty Array (Array of length 0). If list is non-empty, then idArr has 1 or more String items.