function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdcbustedsfdcbusted 

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);
    }

}
Best Answer chosen by sfdcbusted
bob_buzzardbob_buzzard
As far as I know that's the way to do it.  You can clone the record in a controller using the sobject clone() method, as long as it contains all of the fields you are interested in.

All Answers

bob_buzzardbob_buzzard
WRT point 1 - URL hacks don't work on Salesforce1 - if you need to pre-populate fields and publisher actions don't have the flexibility, Visualforce is the only option.  You can then pass information on the URL that your controller can process.
sfdcbustedsfdcbusted
Thanks for the response bob! 

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? 







bob_buzzardbob_buzzard
As far as I know that's the way to do it.  You can clone the record in a controller using the sobject clone() method, as long as it contains all of the fields you are interested in.
This was selected as the best answer
sfdcbustedsfdcbusted
Okay so I can now clone the record from the controller using the clone method + sObjectDescribe to get all the fields. Now the only problem would be is to show this fields on the new visualforce page. It should be exactly how a clone button works so the visualforce page should be on edit mode that shows all the fields on a layout when the user clicks on the custom clone button. 

I think this is getting pretty much complicated just to replicate our custom clone button for salesforce1 app. :(

devindiaadevindiaa
Hello

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
 
bob_buzzardbob_buzzard
I'm not aware of any way to pre-populate fields without using a Visualforce override. The URL hack tricks don't work with Salesforce1.
devindiaadevindiaa
Hey Bob Thanks for replying. Could you explain more in detail. Specifically in my case, how do you suggest I approach the problem.

Many Thanks!
Richy Mishra 7Richy Mishra 7
Bob - do you know if something is Salesforce planning to provide a workaround for URL hacking without using VF pages?