Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Last active January 25, 2019 12:23
Show Gist options
  • Save swapnilshrikhande/bfa56a607e5b6b7e9915a0208324041b to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/bfa56a607e5b6b7e9915a0208324041b to your computer and use it in GitHub Desktop.
Generic Redirect Utility

Usage :

var redirectURL    = getRedirectURL(redirectPage,linkType);
var redirectTo_url = redirectTo('{!recordId}',redirectURL, openInSubtab, actionLabel, linkType );
function redirectTo(recordId,url,openAsSubtab, tabLabel, linkType){
debugger;
if( sforce && sforce.one ){
if ( linkType == 'Standard View'){////replace with variable
sforce.one.navigateToSObject(recordId, view);
} else if ( linkType == 'Standard Edit'){
sforce.one.editRecord(recordId) ;
} else if ( linkType == 'Standard Delete'){
sforce.one.navigateToURL(url,false);
} else {
sforce.one.navigateToURL(url,false);
}
} else if( sforce && sforce.console && sforce.console.isInConsole()) {
var data = {};
data.url = url;
data.tabLabel = tabLabel;
openConsoleTab(data);
} else {
debugger;
if( openAsSubtab ){
window.open(
url,
'_blank' // <- This is what makes it open in a new window.
);
} else {
if (inIframe()) {
window.top.location.href = url;
} else {
window.location.href = url;
}
}
}
}
function getRedirectURL(url, linkType){
var recordId ='{!recordId}';
if ( linkType == '{!VF_TYPE}' ) {
return '/apex/'+url+'?id='+recordId;
} else if ( linkType == '{!URL_TYPE}') {//replace with variable
return url+'?id='+recordId;
} else if ( linkType == '{!STANDARD_VIEW}'){////replace with variable
return '/'+recordId;
} else if ( linkType == '{!STANDARD_EDIT}'){
return '/'+recordId+'/e';
} else if ( linkType == '{!STANDARD_DEL}'){
//todo
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment