当前位置: 首页 > news >正文

在Apex中获取Site URL

Foreword

目前SF暂未提供直接有效的方法在Apex获取SiteURL,我们可以在Idea (Access URL for a Site or Community from Apex)页面投票,除了下面提供的一种hack思路,当然也可以通过Custom Label手动维护。

Format of Site URL

Sandbox site url:
“http://{sandbox-name}–{subdomain}.{salesforce-instance}.force.com”
Enterprise edition site url:
“http://{subdomain}.{salesforce-instance}.force.com” Format of
Developer edition site url:
“http://{subdomain}-developer-edition.{salesforce-instance}.force.com"

Customization

Step 1 : Create a apex class “siteurl” and paste the following code.

public  with sharing  class siteurl{/*** Webkul Software.** @category Webkul* @author Webkul* @copyright Copyright (c) 2010-2018 Webkul Software Private Limited (https://webkul.com)* @license https://store.webkul.com/license.html*/public List getSiteUrl(){ List siteList = [SELECT GuestUserId, Name,MasterLabel, Subdomain, OptionsRequireHttps, UrlPathPrefix FROM Site WHERE Status = 'Active' Limit 1000];List siteFullUrlList = new List();/** We can get instance of the org from organisation object **/Organization org = [SELECT InstanceName,Name, IsSandbox, OrganizationType FROM Organization];if(siteList != null && siteList.size() != 0) {for(Site s: siteList) {if(s.Subdomain != null) {String httpStr = 'http://';if(s.OptionsRequireHttps == true) {httpStr = 'https://';}String siteFullUrl = httpStr;if(org.IsSandbox == true) {siteFullUrl += UserInfo.getUserName().substringAfterLast('.')+'-';}siteFullUrl += s.Subdomain + '.';siteFullUrl += (org.IsSandbox || org.OrganizationType == 'Developer Edition' ? (org.InstanceName.toLowerCase() + '.') : '') + 'force.com';if(s.UrlPathPrefix != null) {siteFullUrl += '/'+s.UrlPathPrefix; }siteFullUrlList.add(siteFullUrl);}}}  return siteFullUrlList;}
}

Step 2 : Create visualforce page with following code.

<apex:page controller="siteurl"><!--/*** Webkul Software.** @category Webkul* @author Webkul* @copyright Copyright (c) 2010-2018 Webkul Software Private Limited (https://webkul.com)* @license https://store.webkul.com/license.html*/--><apex:repeat value = "{!siteurl}" var="s">{!s}<br/></apex:repeat>
</apex:page>

Final Effect

Site URL List in Developer Edition

在这里插入图片描述
在这里插入图片描述

Site URL List in sandbox

在这里插入图片描述

http://www.lryc.cn/news/67643.html

相关文章:

  • 【电子学会】2023年03月图形化三级 -- 比大小.md
  • Kali-linux使用Nessus
  • 青训营 x 训练营结营测试题目(前端方向)
  • 虚拟化技术介绍-VMware和Docker的区别
  • TinyHttpd 运行过程出现的问题
  • 【Linux】shell编程—数组
  • Maven仓库与Maven插件
  • 【溯源反制】CDN域前置云函数-流量分析|溯源
  • 【Vue】学习笔记-全局事件总线
  • MATLAB数值运算(六)
  • 某医院Pad网络故障分析
  • git 撤销中间某次提交,保留其他提交的方法
  • 空中下载技术(OTA)电控信息安全
  • 数据库sql语句(count(*)和count(字段))
  • 短视频矩阵源码系统
  • 检测数据类型
  • 【2023春招】4399 web后台-Java后端开发
  • 干货分享:PCB防静电设计的必要性
  • 电脑压缩包文件不见了怎么办?2种办法轻松找回电脑丢失文件!
  • 如何申请gpt4.0-如何接入ChatGPT4
  • 设计模式-备忘录模式
  • 阿里、京东等大厂年薪50w的测试都是什么水平?
  • Java PECS(Producer Extends Consumer Super)原则
  • Learn RabbitMQ with SpringBoot
  • 定时器 POSIX Timer定时器和setitimer定时器
  • DeSD:用于3D医学图像分割的深度自蒸馏自监督学习
  • MySQL数据库——MySQL创建触发器(CREATE TRIGGER)
  • Java实现网上人才招聘系统【附源码】
  • jmeter接口测试项目实战详解,零基础也能学,源码框架都给你
  • MySQL中去重 distinct 和 group by 是如何去重的