• Deepak Raj 34
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi, I have created a custom button 'Checkin' on opportunity and below is the javascript for this. on cllick of the button, its creating a task under opportunity by saving checkin logtitude latitude.

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

var tsk = new sforce.SObject('Task'); 


tsk.WhatId = '{!Opportunity.Id}'; 
tsk.subject = 'Subject1'; 

if(navigator.geolocation){ 
//browser support geolocation 
navigator.geolocation.getCurrentPosition(callbackSuccess, callbackError,{enableHighAccuracy:true,timeout:3000}); 

}else{ 
alert('Navigation is not supported'); 


function callbackSuccess(position) { 

//get latitude and longitude 
var lat = position.coords.latitude; 
var lon = position.coords.longitude; 

tsk.Checkin_Geolocation__Latitude__s=lat; 
tsk.Checkin_Geolocation__Longitude__s=lon; 
sforce.connection.create([tsk]); 

window.location.reload(); 


function callbackError(error) { 
switch(error.code) { 
case error.UNKNOWN_ERROR: 
alert("UNKNOWN_ERROR."); 
break; 
case error.PERMISSION_DENIED: 
alert("PERMISSION_DENIED."); 
break; 
case error.POSITION_UNAVAILABLE: 
alert("POSITION_UNAVAILABLE."); 
break; 
case error.TIMEOUT: 
alert("TIMEOUT."); 
break; 

}


I am unable to see this button in salesforce1 app in mobile. Any solution for this.? Alternatively, how can we write this in visualforce page.