I would really like to create a button to a joined report that gives information on the current account. I am used to passing parameters in standard reports, but I have found out that I can't do the same for joined reports. And there is an idea up in IdeaExchange.

I did, however, find a link to this post here on this site that shows me how to do this through Java and then the related Github post. I can't comment on them since I don't have enough reputation on the site, nor can I link more than two URLs, sorry.

My report has three blocks, all joined by the Account ID

I am not a coder, but I think I can figure this out with a bit of help. I have a few questions.

1) Since I am just looking for the id of the account, could I just change the var idArray to

var idArray = {!GETRECORDIDS($Account.id)};

2) In the sforce.connection.query, would I just have

("Select Id, from Account where Id = \'" + idToUse + "\'");

Or do I need to include all the fields on all the blocks?

3) With the var postData I (on chrome) used the Form Data : runReportJson and then pressed "view URL encoded". I just copy/pasted this into this section. Is that correct?

4) I don't need to do anything with the information after that, correct?

Sorry for all the simple questions. I'm totally ok with getting a link to somewhere that explains the situation a little better, too. I'm just not at all familiar with JS.

Thank you for any help, though!

1 Answer 1


You need to create a custom link or button on Account object with Content Source
as "Onclick Javascript" and use the code from below, making changes as stated in the code comments. From my experience, Report Id isn't playing any role here, while runReportJson has to be replaced each time you modified the report.How to get to runReportJson string

I prefer to use a real record Id in the filters to test the report, and also it's easier later just to replace this Id in the string with AccountId variable, used as a parameter.

// Original code by Stephen Brown can be found here https://gist.github.com/stephenbrown1/7443749

var url = "YourReportID"; // Doesn't matter at all :)
var AccountId = '{!Account.Id}';
var data = "";


    var postData = "op=run&repId=" + url + "&runReportJson=" + 

// next line is post data, see instructions https://salesforce.stackexchange.com/a/8998/12440
// Click on 'View URL encoded' and copy the entire string from runReportJson under 'Form Data'

// paste what you copied from runReportJson string surrounded with double quotes
// Replace a dummy Account Id used in filters  with: "+ AccountId +"
// it should look like this, but string will be huge:
"%7B%22rt%22%3A%22070F0000000bmEK%22%2C%22charts%22%3A%5B%7B%22fg%22%3A0%2C%22chsv%22%3Afalse%2C%22cheh%22%3Afalse%2C%22cfsize%22%3A12%2C%22chst%22%3Afalse%2C%22Yman%22%3Afalse%2C%22bg2%22%3A16777215"+ AccountId +"%2C%22csize%22%3A3%2C%22l%22%3A%221%22%2C%22chsp%22%3Afalse%2C%22bg1%22%3A16777215%2C%22cp%22%3A%22t%22%2C%22cd0%22%3A%22072F0000006VYRq%22%2C%22ct%22%3A%22column_0%22%2C%22tfg%22%3A0%2C%22ctsize%22%3A18%2C%22bgdir%22%3A%222%22%2C%22"

    var request = new XMLHttpRequest();
        request.open("POST", "/" + url, true);
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        // calling DoWork function below to make it working in IE8 or below, you can remove it if not needed
        request.onreadystatechange = DoWork;

    function DoWork()
        var x="";
        if (request.readyState == 4 && request.status == 200)
            data = request.responseText; // Returned data, e.g., an HTML document.

            if (isIE() == "8" || isIE() == "7" || isIE() == "6")


    function isIE ()
        var myNav = navigator.userAgent.toLowerCase();
        return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;

P.S. I want to thank to Stephen B who provided the original code I tweaked, and also zachelrath for the instructions how to get runReportJson string from this discussion


You must log in to answer this question.

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