Recently was trying to fetch the current location of mine in salesforce, most of the time people use google api's for it, but just dig in a bit and found something way too easy and way too awesome to use, the best part is you can utilize the javascript code without referring any further libraries.
Here I got the example of using geolocation API, this document is the specification defines an API that provides scripted access to geographical location information associated with the hosting device.
here is the sample code that they shared
So to implement this thing I want to check weather it work on normally on Salesforce or not, So I created a detail button on Account to check the code. I created a geolocation type field on Account object, and created a detail button on it adn added it to the layout.
Here is the detail page button "Check-in" and "Geolocation" field, just click on check-in button you will the current geolocation, to know more about the geolocation field click here
Here is the code of the check-in detail button, please put Behavior as Execute JavaScript of the detail button.
Just try above code, it works like charm. Happy to answer any query.
Hope this will help someone.
Happy coding!!
Here I got the example of using geolocation API, this document is the specification defines an API that provides scripted access to geographical location information associated with the hosting device.
here is the sample code that they shared
So to implement this thing I want to check weather it work on normally on Salesforce or not, So I created a detail button on Account to check the code. I created a geolocation type field on Account object, and created a detail button on it adn added it to the layout.
Here is the detail page button "Check-in" and "Geolocation" field, just click on check-in button you will the current geolocation, to know more about the geolocation field click here
Here is the code of the check-in detail button, please put Behavior as Execute JavaScript of the detail button.
1: {
2: !requireScript("/soap/ajax/26.0/connection.js")
3: }
4: navigator.geolocation.getCurrentPosition(function(position) {
5: var longitude = position.coords.longitude;
6: var latitude = position.coords.latitude;
7: var account = new sforce.SObject("Account");
8: account.id = '{!Account.Id}';
9: account.Geolocation__Latitude__s = latitude;
11: account.Geolocation__Longitude__s = longitude;
12: var result = sforce.connection.update([account]);
13: if (result[0].getBoolean("success")) {
14: alert('Account updated successfully');
15: window.location.reload();
16: } else {
17: alert('Error : ' + result);
18: }
19: });
Just try above code, it works like charm. Happy to answer any query.
Hope this will help someone.
Happy coding!!
This is an interesting blog that you have posted, you shares a lot of useful things about Technology.
ReplyDeleteHtml5 Training in Chennai
Html5 Training in Velachery
Html5 Training in OMR
Best DOT NET Training institute in Chennai
asp.net training in chennai
DOT NET Training Institutes in Chennai
Best Html5 Training
IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.
DeleteIEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.
corporate training in chennai corporate training in chennai
corporate training companies in india corporate training companies in india
corporate training companies in chennai corporate training companies in chennai
I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai
I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeleteRegards,
PHP Training in Chennai
PHP Course in Chennai
Tally Course in Chennai
ReactJS Training in Chennai
microsoft dynamics crm training in chennai
PHP Training in Chennai
PHP Course in Chennai
This is the best post for developing my knowledge and Keep posting. Thank you for sharing with us...!
ReplyDeleteSpark Training in Chennai
Spark Training
Pega Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Linux Training in Chennai
Social Media Marketing Courses in Chennai
Power BI Training in Chennai
Tableau Training in Chennai
Awesome informations that you have shared for us.I eagerly waiting for more updates in future.
ReplyDeleteHadoop Training in Chennai
Big data training in chennai
hadoop training in velachery
JAVA Training in Chennai
Python Training in Chennai
Selenium Training in Chennai
hadoop training in velachery
big data training in velachery
Hadoop Training in OMR
Big Data Training in OMR
Thanks for sharing the article. Keep sharing your ideas with us.
ReplyDeleteEthical Hacking course in Chennai
Ethical Hacking Training Institute in Chennai
Hacking course in Chennai
ccna Training in Chennai
Salesforce course in Chennai
PHP Training in Chennai
Tally course in Chennai
Ethical Hacking course in OMR
Ethical Hacking course in Anna Nagar
Ethical Hacking course in Vadapalani
I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeleteRegards,
Azure Training in Chennai
Azure Training center in Chennai
Azure courses in Chennai
R Training in Chennai
Vmware cloud certification
RPA Training in Chennai
DevOps certification in Chennai
Azure Training in Anna Nagar
Azure Training in T Nagar
Azure Training in OMR
Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
ReplyDeleteJob in Dubai
ReplyDeleteI have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
best software testing training in chennai
best software testing training institute in chennai with placement
software testing training
courses
software testing training and placement
software testing training online
software testing class
software testing classes in chennai
best software testing courses in chennai
automation testing courses in chennai
I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision.keep blogging.
ReplyDeleteDigital Marketing Course In Kolkata
Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way. T hank you so much.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
Hi,
ReplyDeleteI'm getting the error requireScript is not defined.
Please help.
Regards,
I was following your blog regularly and this one is very interesting and knowledge attaining. Great effort ahead. you can also reach us for web development company in chennai website design company in chennai
ReplyDeleteThanks for giving great kind of information
ReplyDeletelearn salesforce online
salesforce online training in hyderabad
nice post.salesforce training
ReplyDeletesalesforce online training
salesforce online course