You need to sign in to do that
Don't have an account?
Chanagan Sakulteera
Publisher Action & Visualforce Page Question
I am having trouble with one of my visualforce page that I want to be able to run in the Salesforce1 App. Right now it is working perfectly if I use a custom link to open up the VF page. But when I try to open the page up from the publisher action instead, it will not work. Please find my controller and VF page below:
Apex Class
global with sharing class LeadController{
public Id leadId{
get{
return Id.valueOf(ApexPages.CurrentPage().getparameters().get('id'));
}
}
private Lead lead{get; set;}
public String lat{
get{
if(lead == null || lead.Location__Latitude__s == null)
return 'null';
return lead.Location__Latitude__s + '';
}
}
public String lng{
get{
if(lead == null || lead.Location__Longitude__s == null)
return 'null';
return lead.Location__Longitude__s + '';
}
}
global leadController(ApexPages.StandardController controller) {
lead = [select Id, Location__Latitude__s, Location__Longitude__s from Lead where Id = :leadId];
}
public PageReference test(){
return null;
}
@RemoteAction
global static String Checkin(Id planId, Double latitude, Double longitude){
Lead checkin = new Lead(
Id = planId
, Location__Latitude__s = latitude
, Location__Longitude__s = longitude
);
update checkin;
system.debug('Lead: ' + checkin);
return checkin.Id;
}
}
Visualforce Page
<apex:page standardController="Lead" extensions="LeadController" sidebar="false" showHeader="false">
<script>
(function () {
var leadId = '{!leadId}';
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
console.log(position.coords);
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.LeadController.Checkin}'
, leadId
, position.coords.latitude
, position.coords.longitude
, function(result, event){
//window.location = "../../../" + leadId;
window.history.back();
},
{escape: true}
);
});
} else {
alert('This device does not support Geolocation operation.');
//window.location = "../../../" + leadId;
window.history.back();
}
})();
</script>
<div style="text-align:center;height: 100%;padding-top: 10%;">
<img src="../../../../resource/0/loading"/>
</div>
</apex:page>
Thank you inadvance.
Apex Class
global with sharing class LeadController{
public Id leadId{
get{
return Id.valueOf(ApexPages.CurrentPage().getparameters().get('id'));
}
}
private Lead lead{get; set;}
public String lat{
get{
if(lead == null || lead.Location__Latitude__s == null)
return 'null';
return lead.Location__Latitude__s + '';
}
}
public String lng{
get{
if(lead == null || lead.Location__Longitude__s == null)
return 'null';
return lead.Location__Longitude__s + '';
}
}
global leadController(ApexPages.StandardController controller) {
lead = [select Id, Location__Latitude__s, Location__Longitude__s from Lead where Id = :leadId];
}
public PageReference test(){
return null;
}
@RemoteAction
global static String Checkin(Id planId, Double latitude, Double longitude){
Lead checkin = new Lead(
Id = planId
, Location__Latitude__s = latitude
, Location__Longitude__s = longitude
);
update checkin;
system.debug('Lead: ' + checkin);
return checkin.Id;
}
}
Visualforce Page
<apex:page standardController="Lead" extensions="LeadController" sidebar="false" showHeader="false">
<script>
(function () {
var leadId = '{!leadId}';
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
console.log(position.coords);
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.LeadController.Checkin}'
, leadId
, position.coords.latitude
, position.coords.longitude
, function(result, event){
//window.location = "../../../" + leadId;
window.history.back();
},
{escape: true}
);
});
} else {
alert('This device does not support Geolocation operation.');
//window.location = "../../../" + leadId;
window.history.back();
}
})();
</script>
<div style="text-align:center;height: 100%;padding-top: 10%;">
<img src="../../../../resource/0/loading"/>
</div>
</apex:page>
Thank you inadvance.
Shashank (Salesforce Developers)
Please refer to the samples in thiis page and see if you can find any disprepancies: https://help.salesforce.com/apex/HTViewHelpDoc?id=creating_vf_pages_for_custom_actions.htm&language=en_US