You need to sign in to do that
Don't have an account?
sfdcbusted
Salesforce1 Custom Button URL Redirection
Hi
Quite having a problem enabling custom buttons using visualforce page on Salesforce1.
So here’s the situation, we currently have converted an onClick javascript Clone button to a visualforce page and it is working as expected on our salesforce full site, but when it comes to the Salesforce1 app were having a problem with the behaviour of the custom button.
1. Does URL redirections work the same for salesforce1? I mean the URL hacks that we can do for the salesforce full site just like the one on the controller below which is the URL hack for cloning records and passing additional parameters to pre-populate record details upon cloning a record.
return new PageReference('/'+ camp.Id + '/e?clone=1&00NC0000005Ijnf=Clone&00NC0000005Ijne='+ camp.Id + '&00NC0000005CNRZ=1');
2. Is there other way of customizing the clone button on salesforce1 other than overriding it with visualforce page? Already tried using URL link buttons didn’t work either.
Here's the code:
VF Page:
<!-- PSDS 1/27/2014 -D-3063 - SF1 Enhancement - convert campaign clone javascript to visualforce page to enable it on Salesforce1 App -->
<apex:page standardController="Campaign" extensions="CampaignCloneController" action="{!init}">
<apex:form >
<apex:actionFunction action="{!redirect}" name="redirect"/>
<apex:actionFunction action="{!cancel}" name="cancel"/>
</apex:form>
<script>
var allowed = {!allowed};
<!-- Validate if user is allowed to clone campaign -->
function validate() {
if(allowed == false) {
alert('Only Email campaigns with "Test" in the campaign name can be cloned');
cancel();
}
}
validate();
</script>
</apex:page>
Controller:
public class CampaignCloneController {
public string campaignID {get; set;}
public Campaign camp {get; set;}
static string profileName;
public boolean allowed{get;set;}
/*
@description: User using the clone button
*/
static{
profileName = [SELECT Name FROM Profile WHERE Id =: UserInfo.getProfileID()].Name;
}
/*
@description: Verifies if the user is allowed to use the clone button
*/
public CampaignCloneController(ApexPages.StandardController controller) {
camp = [SELECT Id, RecordType.Name, Name FROM Campaign WHERE Id =: controller.getID()];
if((profileName.toUpperCase().contains('STANDARD') && !camp.RecordType.Name.toUpperCase().contains('EMAIL'))
||(profileName.toUpperCase().contains('STANDARD')
&& camp.RecordType.Name.toUpperCase().contains('EMAIL')
&& !camp.Name.toUpperCase().contains('TEST'))) {
allowed = false;
} else {
allowed = true;
}
}
public PageReference init() {
if(allowed == true) {
return redirect();
} else {
return null;
}
}
/*
@description redirects page to clone page
*/
public PageReference redirect(){
return new PageReference('/'+ camp.Id + '/e?clone=1&00NC0000005Ijnf=Clone&00NC0000005Ijne='+ camp.Id + '&00NC0000005CNRZ=1');
}
public PageReference cancel(){
return new PageReference('/' + camp.Id);
}
}
Quite having a problem enabling custom buttons using visualforce page on Salesforce1.
So here’s the situation, we currently have converted an onClick javascript Clone button to a visualforce page and it is working as expected on our salesforce full site, but when it comes to the Salesforce1 app were having a problem with the behaviour of the custom button.
1. Does URL redirections work the same for salesforce1? I mean the URL hacks that we can do for the salesforce full site just like the one on the controller below which is the URL hack for cloning records and passing additional parameters to pre-populate record details upon cloning a record.
return new PageReference('/'+ camp.Id + '/e?clone=1&00NC0000005Ijnf=Clone&00NC0000005Ijne='+ camp.Id + '&00NC0000005CNRZ=1');
2. Is there other way of customizing the clone button on salesforce1 other than overriding it with visualforce page? Already tried using URL link buttons didn’t work either.
Here's the code:
VF Page:
<!-- PSDS 1/27/2014 -D-3063 - SF1 Enhancement - convert campaign clone javascript to visualforce page to enable it on Salesforce1 App -->
<apex:page standardController="Campaign" extensions="CampaignCloneController" action="{!init}">
<apex:form >
<apex:actionFunction action="{!redirect}" name="redirect"/>
<apex:actionFunction action="{!cancel}" name="cancel"/>
</apex:form>
<script>
var allowed = {!allowed};
<!-- Validate if user is allowed to clone campaign -->
function validate() {
if(allowed == false) {
alert('Only Email campaigns with "Test" in the campaign name can be cloned');
cancel();
}
}
validate();
</script>
</apex:page>
Controller:
public class CampaignCloneController {
public string campaignID {get; set;}
public Campaign camp {get; set;}
static string profileName;
public boolean allowed{get;set;}
/*
@description: User using the clone button
*/
static{
profileName = [SELECT Name FROM Profile WHERE Id =: UserInfo.getProfileID()].Name;
}
/*
@description: Verifies if the user is allowed to use the clone button
*/
public CampaignCloneController(ApexPages.StandardController controller) {
camp = [SELECT Id, RecordType.Name, Name FROM Campaign WHERE Id =: controller.getID()];
if((profileName.toUpperCase().contains('STANDARD') && !camp.RecordType.Name.toUpperCase().contains('EMAIL'))
||(profileName.toUpperCase().contains('STANDARD')
&& camp.RecordType.Name.toUpperCase().contains('EMAIL')
&& !camp.Name.toUpperCase().contains('TEST'))) {
allowed = false;
} else {
allowed = true;
}
}
public PageReference init() {
if(allowed == true) {
return redirect();
} else {
return null;
}
}
/*
@description redirects page to clone page
*/
public PageReference redirect(){
return new PageReference('/'+ camp.Id + '/e?clone=1&00NC0000005Ijnf=Clone&00NC0000005Ijne='+ camp.Id + '&00NC0000005CNRZ=1');
}
public PageReference cancel(){
return new PageReference('/' + camp.Id);
}
}
All Answers
So if I want to mimic the standard clone button on salesforce1, I have to create a visualforce page with all the fields of the record being cloned?
I think this is getting pretty much complicated just to replicate our custom clone button for salesforce1 app. :(
Are you able to prepopulate values? Basically any answers to question 2.
I also have same situation - Having a page on Opportunity which gives a link to create new contact but few fields should be automatically populated. I have tried numerous ways but no luck. Pls share your code if you are able to crack it.
Thanks
Many Thanks!