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
sandy18031985sandy18031985 

Custom Button Salesforce1

Hello Everyone,

i have a custom button in my custom object where i am calling a java script. what it does is i gets the values and updates the custom field in the object. 

this working perfect in my laptop but in salesforce1 i cant see the custombutton. what i had read in documnets is that custom buttons are not supported in salesforce1.

i should use a publisher actions only for salesforce1. can any one please tell me how to use this in actions :

{!REQUIRESCRIPT ("/soap/ajax/34.0/connection.js")} 

if (navigator.geolocation) { 
var setPosition = function (position) { 
var visitId = "{!Visitas__c.Id}"; 
var userId = "{!$User.Id}"; 

//console.log("Latitude: " + position.coords.latitude + "\nLongitude: " + position.coords.longitude); 

var visit = new sforce.SObject("Visitas__c"); 

visit.set("Id", visitId); 
visit.set("Local_do_Check_In__Latitude__s", position.coords.latitude ); 
visit.set("Local_do_Check_In__Longitude__s", position.coords.longitude ); 
visit.set("Data_e_Horario_de_Check_In__c", new Date().toISOString() ); 

var result = sforce.connection.update([visit]); 

if (result[0].getBoolean("success") == false) { 
alert("Erro ao atualizar os dados da visita."); 

else { 
function redirect() { parent.frames.location.replace("/{!Visitas__c.Id}"); } 
redirect(); 
window.close(); 

}; 

navigator.geolocation.getCurrentPosition(setPosition); 
} else { 
alert("Este navegador não suporta geolocalização."); 
}


how can i use this in publisher actions. 


Thanks in advance 
Ajay K DubediAjay K Dubedi
Custom buttons with Javascript are not available in Salesforce1, and it is expected functionality.
You have to move your javascript in visualforce page and use this visual force page for custom button.
This way, the custom button will be available in Salesforce1 but take care that your visualforce page has  "Available for Salesforce mobile apps" 
option enabled.
kgilkgil
This is just a rough outline expanding on Ajay's response. You will need to create a new Visualforce page and assign it the standardController attribute for your object, ensuring it has the "Available for Salesforce mobile apps" option enabled as mentioned earlier. 

e.g. start with something like:
<apex:page standardController="CustomObjectName__c" showHeader="false" standardStylesheets="false" >

You will need to require your script differently as in this example shown in the AJAX Toolkit Developer's Guide (https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm):
<script src="../../soap/ajax/34.0/connection.js" type="text/javascript"></script>
Then you will need to wrap all this JavaScript in script tags:
<script>

  [all of your existing JavaScript can be pasted here]

</script>
I can not guarantee if you will need any other changes in your JavaScript without testing it out, but the merge fields should work the same since this action is launched from a specific record.

Finally you need to create an action under Objects > Your custom object > Buttons, Links, and Actions, and set the new action source to use this Visualforce page.