4

I have a Home Custom Link Url like this: {!$Site.OriginalUrl}/00O5B000000OL93 that points to a report. I need to be able to change that hardcoded ID with something that won't break once I deploy this to different Sandboxes or Production . What do you guys recommend?

7

I believe the only way to to it would be to use a VF page as the Link and use an action method to navigate to the report.

In the VF page controller query for the report by name:

 <page name="reportRedirect" controller="controllername" action="{!gotoReport}">

    .......No content needed here unless you want it like a waiting spinner or something .....

 </page>


public pageReference gotoReport(){

    Report[] rpt = [Select Id, Name From Report Where Name = 'XYZ'];
    if(rpt.isEmpty()) return null;//Error handling here. Maybe show something on page

    PageReference pr = New PageReference('/' + rpt[0].Id);
    return pr;

{
  • If you use this solution, I think it is rather important to filter by FolderName, as well. I'm not sure if DeveloperName is unique outside of a folder. – Charles Koppelman Mar 29 '17 at 15:38
  • @CharlesKoppelman - Good point, not sure either. – Eric Mar 29 '17 at 15:40
  • @Eric the DeveloperName is not unique but for now, that'll fix the "issue". Thanks Eric and thanks Charles! – The Ghost Mar 29 '17 at 18:36
0

There are two ways I'd answer this question, but both are pretty terrible.

  1. Deploy the report first, then refresh a Sandbox. Your report's Id won't change.

  2. Deploy a Custom Setting that you manually update on deploy to production. You can automate the "manual" update as much as you'd like.

These only work if you have exactly one production org. If you develop for multiple orgs, you'll probably be best either automating #2 on install of your package using the now-famous mdapi package from FinancialForce, or use Eric's solution.

I suggest Custom Settings and not Custom Metadata because we cannot yet access Custom Metadata in formulas.

-1

If it goes to an internal SF report why not make it just /00O5B000000OL93? It's a relative link and Salesforce will fill in the appropriate before parts so it can be dynamic between production and sandbox.

  • 1
    The point is that Ids don't migrate... – Adrian Larson Mar 29 '17 at 15:30
  • @AdrianLarson Is that true if you are deploying using the Metadata API to deploy from a Sandbox to Production? Is that true if you're using a Changeset to deploy from Sandbox to Production? – Charles Koppelman Mar 29 '17 at 15:43
  • 1
    That is true in both cases. Ids are only identical at the instant when you refresh a Sandbox from its parent. Immediately after that, the Ids diverge again. – Sebastian Kessel Mar 29 '17 at 15:45

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.