【问题标题】:Apex salesforce pagereference for URL link mergefieldURL 链接合并字段的 Apex Salesforce 页面参考
【发布时间】:2019-09-28 07:56:06
【问题描述】:

假设创建了一个链接并指向具有以下模式的 URL: /00O70000001SOsa?pv0={!Account.Id}&pv1={!Case.IsClosed} 如果我必须使用 pagereference 或任何其他类似 API 调用相同的东西,这怎么能写在 Apex 控制器中。

【问题讨论】:

    标签: report apex visualforce salesforce-lightning


    【解决方案1】:
    // You will have to apply your own logic on how you pick data for the link
    Account acc = [SELECT Id FROM Account LIMIT 1];
    Case c = [SELECT IsClosed FROM Case LIMIT 1];
    
    Pagereference pr = new PageReference('/00O70000001SOsa');
    pr.getParameters().putAll(new Map<String, String>{
        'pv0' => acc.Id,
        'pv1' => c.isClosed ? 'true' : 'false'
    });
    
    System.debug(pr.getUrl());
    // outputs something like /00O70000001SOsa?pv0=0017000001TSmKmAAL&pv1=false
    

    您传递给 URL 的参数必须是字符串(或容易转换为字符串的东西)。因此,您的工作是转换布尔值,以其他页面“喜欢”的格式显示日期(报告需要与用户使用相同格式的日期,因此根据他/她的语言环境,查看 Date 和 DateTime 中的 format 方法类)。

    但就是这样。您不必担心“?”符号或任何特殊字符的花哨转义,都会为您完成:

    Pagereference pr = new PageReference('/home/home.jsp');
    pr.getParameters().putAll(new Map<String, String>{
        'spaces' => 'spa ce',
        'html-entities' => '& < >',
        'percents' => '1 / 4 = 25%'
    });
    
    System.debug(pr.getUrl());
    // /home/home.jsp?html-entities=%26+%3C+%3E&percents=1+%2F+4+%3D+25%25&spaces=spa+ce
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多