You need to sign in to do that
Don't have an account?
Suneel#8
anchor tag not working in Desktop or Salesforce1
I am dispalying marker for every near by account and below anchor tag should navigate to the respective account upon clicking it.I have used the code in Workbook,but it works neither in Desktop nor in Salesforce1.Please help
try{
if(sforce.one){
accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')';
}
} catch(err) {
console.log(err);
var dId=account.Id;
accountNavUrl= '\\' + account.Id;
}
console.log('-->'+accountNavUrl );
var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;
Below is the whole code
try{
if(sforce.one){
accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')';
}
} catch(err) {
console.log(err);
var dId=account.Id;
accountNavUrl= '\\' + account.Id;
}
console.log('-->'+accountNavUrl );
var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;
Below is the whole code
<apex:page standardController="Account" extensions="AccountMapExt" sidebar="false" showHeader="false"> <!-- Begin Default Content REMOVE THIS --> <apex:includeScript value="https://maps.googleapis.com/maps/api/js?sensor=false" /> <style> html, body { height: 100%; } .page-map, .ui-content, #map-canvas { width: 100%; height:100%; padding: 0; } #map-canvas { height: min-height: 100%; } </style> <script> var lat; var lon; function initialize(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition( function(position){ lat=position.coords.latitude; lon=position.coords.longitude; Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AccountMapExt.getNearby}',lat, lon, function(result, event){ if (event.status) { console.log('->'+lat+' '+lon+' '+result); createMap(lat, lon, result); } else if (event.type ==='exception') { //exception case code } else { } }, {escape: true} ); } ); } } function createMap(lat,lon,accounts){ console.log('Calling map '+ lat+' '+lon); var currentPosition = new google.maps.LatLng(lat,lon); var mapDiv = document.getElementById('map-canvas'); var map = new google.maps.Map(mapDiv, { center: currentPosition, zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var positionMarker = new google.maps.Marker({ map: map, position: currentPosition, icon: 'https://maps.google.com/mapfiles/ms/micons/green.png' }); for(var i=0; i<accounts.length;i++){ account= accounts[i]; console.log(accounts[i]); setupMarker(); } function setupMarker(){ var accountNavUrl; try{ if(sforce.one){ accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')'; } } catch(err) { console.log(err); var dId=account.Id; accountNavUrl= '\\' + account.Id; } console.log('-->'+accountNavUrl ); var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry; //Create the callout that will pop up on the marker var infowindow = new google.maps.InfoWindow({content: content}); //Place the marker var marker = new google.maps.Marker({ map: map, position: new google.maps.LatLng(account.BillingLatitude,account.BillingLongitude)} ); google.maps.event.addListener(marker, 'click', function(){ infowindow.open(map, marker); }); } var mapBoundary = new google.maps.LatLngBounds(); mapBoundary.extend(currentPosition); } google.maps.event.addDomListener(window, 'load', initialize); </script> <body style="font-family: Arial; border: 0 none;"> <div id="map-canvas"></div> </body> <!-- End Default Content REMOVE THIS --> </apex:page>
All Answers
Please try with below code..
Please check with above and let me know if it helps you..
Thanks,
Sandeep
accountNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + account.Id + '\')';
var content='<a href src="'+accountNavUrl +'" >'+account.Name+ '</a><br/>'+account.BillingStreet +'<br/>' + account.BillingCity +'<br/>' + account.BillingCountry;
I have shared my old code which redirects to edit page, you can assign your urlk detail page url to redoirect..
for detail page you can use.
sforce.one.navigateToSObject(recordId);
You can easily customize it..onclickj of any link you can simply call one javascript function and there you can use above code to redirect
sforce.one.navigateToSObject(recordId);.
then it should work..
That was my old which I shared for just a reference so ...
Let me know if you have nay question..
Thanks,
Sandeep
Though I have got this working with above approach,I am inclined to try your idea as well.I am able to implement your idea in Salesforce1 but it is not working in Desktop.Could you please check below code and suggest any corrections.window.location.href or the format of the input doesn't seems to work. Thanks for staying with me!
What you want exactly..for desktop you can simply use window.open...