Skip to content

Instantly share code, notes, and snippets.

@srujan21
Created June 17, 2020 05:04
Show Gist options
  • Save srujan21/1ae03661243adb9c17685a5fe16818d3 to your computer and use it in GitHub Desktop.
Save srujan21/1ae03661243adb9c17685a5fe16818d3 to your computer and use it in GitHub Desktop.
<apex:page showHeader="true">
<script>
var cPattern = 'curl=';
var lPattern = 'lurl=';
var fullUrl = document.URL;
var curl;
var lurl;
if(!(fullUrl.includes(cPattern) && fullUrl.includes(lPattern))) {
alert('Missing required parameters.');
throw new Error('Missing required parameters');
}
// classic url slice
curl = fullUrl.substring(
fullUrl.indexOf(cPattern) + cPattern.length,
fullUrl.indexOf(lPattern)
);
//lightning url slice
lurl = fullUrl.substring(fullUrl.indexOf(lPattern) + lPattern.length);
if (UITheme.getUITheme() === 'Theme4d' ||
UITheme.getUITheme() === 'Theme4u' ||
UITheme.getUITheme() === 'Theme4t')
{
//lightning experiance comes with encoded URLs, decoding for lightning framework to handle navigation
lurl = decodeURIComponent(lurl);
sforce.one.navigateToURL(lurl);
}
else
{
window.top.location = curl;
}
</script>
<!-- /apex/LightningUrlRedirect?curl=/a9c/e?RecordType=0121W0000005j2i&CF00N1W000002xYNs={!Service_Request__c.Opportunity__c}&CF00N1W000002xYNs_lkid={!Service_Request__c.OpportunityId__c}&CF00N40000002rkbn={!Service_Request__c.Construction_Job__c}&CF00N40000002rkbn_lkid={!Service_Request__c.Construction_JobId__c}&CF00N40000002rkbp= {!Service_Request__c.Name}&CF00N40000002rkbp_lkid= {!Service_Request__c.Id}
&retURL=%2F{!Service_Request__c.Id}
&cancelURL=%2F{!Service_Request__c.Id}
&lurl=/lightning/o/PMO_Risk_Management__c/new?defaultFieldValues=Related_Service_Request__c={!Service_Request__c.Id},Related_Opportunity__c={!Service_Request__c.OpportunityId__c},Related_Construction_Job__c={!Service_Request__c.Construction_JobId__c},RecordType=0121W0000005j2i&retURL=%2F{!Service_Request__c.Id}&cancelURL=%2F{!Service_Request__c.Id} -->
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment