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
Katrina_HarshKatrina_Harsh 

Recreate buttons from "Execute JavaScript" to Visualforce

To anyone who can point me in the right direction.  I have done a lot of research, but can't seem to find the correct solution to my issue.

I need to take two buttons that we have created on Salesforce Classic, using the behavior Execute JavaScript, and recreate them using Visualforce.  Our issue is that the buttons show up on our computers, but it not available through the mobile app.

These are the two buttons we currently have,

User-added image
User-added image

Can anyone offer guidance on where to go.  I am aware I need to create a controller/apex class, but this is a little out of my knowledge base and I would like to learn how to go about recreating these buttons so they function online and on mobile.

Thanks,

Katrina Harsh
Best Answer chosen by Katrina_Harsh
pconpcon
That's really easy to do.  First you want to go into your Visualforce pages and make sure they are enabled for Salesforce1

User-added image
Then you have a choice.  You can use the Custom Button approach that will be available in both Classic and Salesforce1 / Lightning Experience but you cannot set the icon for this.  To do that you just goto Setup ⇨ Customize ⇨ Leads ⇨ Buttons, Links, and Actions ⇨ New Button or Link and fill out the following

User-added image

Your other option is to add it as a Visualforce page action.  This will only be available in Salesforce1 / Lightning Experience but you can customize the icon.
User-added image
Then once you have your action / button created you add it to the Salesforce1 and Lightning Experience Actions section of the page layout
User-added image
If you want it for classic you'd also add your Custom Button there.

Then you're good to go and you'll see it in Salesforce1

User-added image

You can also do both a button for classic and an action for Salesforce1 but it's a little tough to tell them apart (without trial and error) if you give them the same label.

All Answers

pconpcon
This is a pretty simple thing to do.  Below is the code to do it.

AcceptLead.cls
public class AcceptLead {
    public Lead l;
    
    public AcceptLead(ApexPages.StandardController controller) {
        this.l = (Lead) controller.getRecord();
    }
    
    public PageReference pageAction() {
        this.l.Locked__c = false;
        this.l.Lead_Stage__c = '03 - SAL';
        this.l.Lead_Accepted_Rejected__c = 'Accepted';
        
        update this.l;
        
        return new PageReference('/' + this.l.Id);
    }
}

AcceptLead.vfp
<apex:page standardController="Lead" extensions="AcceptLead" action="{!pageAction}">
</apex:page>

RejectLead.cls
public class RejectLead {
    public Lead l;
    
    public RejectLead(ApexPages.StandardController controller) {
        this.l = (Lead) controller.getRecord();
    }
    
    public PageReference pageAction() {
        this.l.Locked__c = false;
        this.l.Status = '02 - Working/In Progress';
        this.l.Lead_Stage__c = '05 - SRL';
        this.l.Lead_Accepted_Rejected__c = 'Rejected';
        //this.l.OwnerId = 'xxxxx';
        
        update this.l;
        
        return new PageReference('/' + this.l.Id);
    }
}
RejectLead.vfp
<apex:page standardController="Lead" extensions="RejectLead" action="{!pageAction}">
</apex:page>

You will need to update line 13 of RejectLead.cls to set your owner id and uncomment the line.  Then you just create Visualforce buttons for each of these and add it to your page layout.
 
Katrina_HarshKatrina_Harsh

PCon,

Thank you for the help,  but how do I go about setting these actions up on the mobile app?

I have the coding added to our org, and they work well as buttons on the desktop, but when I go into the mobile app they don't even appear.  How can I go about changing that?

Thanks,
 

Katrina

pconpcon
That's really easy to do.  First you want to go into your Visualforce pages and make sure they are enabled for Salesforce1

User-added image
Then you have a choice.  You can use the Custom Button approach that will be available in both Classic and Salesforce1 / Lightning Experience but you cannot set the icon for this.  To do that you just goto Setup ⇨ Customize ⇨ Leads ⇨ Buttons, Links, and Actions ⇨ New Button or Link and fill out the following

User-added image

Your other option is to add it as a Visualforce page action.  This will only be available in Salesforce1 / Lightning Experience but you can customize the icon.
User-added image
Then once you have your action / button created you add it to the Salesforce1 and Lightning Experience Actions section of the page layout
User-added image
If you want it for classic you'd also add your Custom Button there.

Then you're good to go and you'll see it in Salesforce1

User-added image

You can also do both a button for classic and an action for Salesforce1 but it's a little tough to tell them apart (without trial and error) if you give them the same label.
This was selected as the best answer
Katrina_HarshKatrina_Harsh

PCon,

Thank you so much for the help!  It works!  Now I know how to translate Java codes for future!
 

Thanks again,
 

Katrina Harsh