+ Start a Discussion
Uttpal chandraUttpal chandra 

How to get id when user click on Detail Page Button

Hi All,
Currently When a user is clicking on Detail Page Button I am loading a javscript to create a Pop up. But I am not able to fetch Id of a record.

Anyone help me on this.

javascriptcode
(function() {
    var width = 500;
    var height = 300;
    var title = "Run Template";

    var box = new SimpleDialog("salesforce" + Math.random(), true);
    box.setTitle(title);
    box.displayX = true;
    box.isMovable = false;
    box.createDialog();
    box.setWidth(width);
    // set your html content here
    box.setContentInnerHTML(
      '<iframe src="/apex/RunTemplate" style="border:none;" width="100%" height="'+ (height - 30)+'px" />'
    );
    //set the height of the modal
    box.dialog.children[1].style.height = height + 'px';
    box.show();

    //if displayX is set to true, then override standard close event by this code
    box.dialog.getElementsByClassName('dialogClose')[0].onclick = function() {
      box.hide();
      // you can add code to reload the page or redirect to another page 
    };
    //optional : add this to close the modal onclick of the overlay background
    box.background.addEventListener('click', function() {
      box.hide();
    });
    
    // if you want to be able to close the modal from the Visualforce page
    window.addEventListener('message', function(event){
      if (event.data === 'close'){
        box.hide();
      }
    });
})();

Thanks in advance
Deepali KulshresthaDeepali Kulshrestha
Hi Uttpal,
The code for this button looks like this:

var leadIds = {!GETRECORDIDS($ObjectType.Lead)};
if (!leadIds || leadIds.length < 1) {
alert('Please select at least one Contact to upload.');
} else {
var baseUrl;

var hostnameParts = location.hostname.split('.');
if (hostnameParts[0] == 'ctct2') {
baseUrl = '<a href="https://ctct2.%27" target="_blank" rel="nofollow">https://ctct2.'</a> + hostnameParts[1] + '.visual.force.com';
} else {
baseUrl = '<a href="https://ctct2.%27" target="_blank" rel="nofollow">https://ctct2.'</a> + hostnameParts[0] + '.visual.force.com';
}

var form = document.createElement('form');
form.action = baseUrl + '/apex/UploadWizardStep1';
form.method = 'post';

var hiddenTypeField = document.createElement('input');
hiddenTypeField.id = 'type';
hiddenTypeField.name = 'type';
hiddenTypeField.type = 'hidden';
hiddenTypeField.value = 'Lead';
form.appendChild(hiddenTypeField);

var hiddenUploadIdsField = document.createElement('input');
hiddenUploadIdsField.id = 'uploadIds';
hiddenUploadIdsField.name = 'uploadIds';
hiddenUploadIdsField.type = 'hidden';
hiddenUploadIdsField.value = leadIds;
form.appendChild(hiddenUploadIdsField);

document.body.appendChild(form);

form.submit();
}

Please replace Line one with below given line of code, 
I am working for lead you can replace with any object.

var leadIds = '{!Lead.Id}';

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha