3

I am trying to build a javascipt custom button that launches a google hangout and calls with person's phone number on the Lead record. Google has indicated this is what a page with a google hangouts button would look like:

https://developers.google.com/+/hangouts/button

Couldn't post the code here, but go to the Basic page with a phone number invite section.

So far I imagine the button would need look something like this, but if someone who is more familiar with javascript help that would be great:

{!REQUIRESCRIPT("https://apis.google.com/js/platform.js")}
<g:hangout render="createhangout"
    invites="[{ id : '{!Lead.Phone}', invite_type : 'PHONE' }]">
</g:hangout>

Update:

Thank you. I am trying to pass the phone number parameter in too. This is what I have so far, but it just opens a blank hangout window. Any advice?

> var gHangout_buttonImplemented = false;
jQuery(function(){
    if(!gHangout_buttonImplemented){
        gHangout_buttonImplemented=true;
        //assuming the name of the button is gHangout.
        //Hide the actual button and show the hangout butotn.
        jQuery("[value=gHangout]").hide().after('<div id="hangoutDiv"></div>');
        gapi.hangout.render('hangoutDiv', { 'render': 'createhangout'});
        gapi.hangout.invite('hangoutDiv', {'id': '8019010856', 'invite_type': 'PHONE'});

    }
});
  • If you're posting that into a Javascript custom button, it won't work as the second part is markup not Javascript. See the "Render button using JavaScript" example on the page you linked to - the Javascript grabs the div with the ID and renders the hangout button into it. You'll need to do something similar. Hopefully someone will be along with some ideas for you. – GBreavin Feb 24 '15 at 5:57
  • Yes, I posted the javascript into a static resource inside of salesforce. I tried modifying the code from the suggestion to designate the hangout is a call (shown in the update above) , but it does not work. Any tips? – Paul Fischer Feb 27 '15 at 2:43
1

The custom button cannot contain anything but javascript. If you want to add any HTML or CSS then you will have to do it via javascript. In the below code I have included 3 scripts first is the jquery (It's up to you if you want to use it, I use it for DOM manipulation as its very simple), second one is js file from google and 3rd one is a file which has the code to create the button and this is stored in Static Resources.

The reason the javascript code is added in the file and not directly in the button is because the javascript added as files are invoked immediately when the page is loaded and the js in the button will be executed only when a user clicks on it.

Button Code:

{!REQUIRESCRIPT('//code.jquery.com/jquery-1.11.2.min.js')}
{!REQUIRESCRIPT('https://apis.google.com/js/platform.js')}
{!REQUIRESCRIPT('/resource/gHangoutjs?ver=003')}

gHangoutjs:

var gHangout_buttonImplemented = false;
jQuery(function(){
    if(!gHangout_buttonImplemented){
        gHangout_buttonImplemented=true;
        //assuming the name of the button is gHangout.
        //Hide the actual button and show the hangout butotn.
        jQuery("[value=gHangout]").hide().after('<div id="hangoutDiv"></div>');
        gapi.hangout.render('hangoutDiv', { 'render': 'createhangout' });
    }
});

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.