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
NM AdminNM Admin 

Fetch current logged in users location for every hour and store it into the custom object.

Here is the detailed requirement:
I have requirement in that I wan to fetch current logged in users location(Latitude and Longitude) and store the information into the custom object to show google map. I also want to fetch the same information every hour by using scheduled batch class and store the info in to the custom object.


So the challange is that I have done the requirement by using visualforce page but I'mmnot able to schedule the page OR refresh the page from teh batch class.


Can we do this using batch class? Can we navigate to the visual force page from batc class?Can we achieve this without using  javascript? OR is there alternative solution to achieve this requirement?


Welcome to youe suggestion!


Thanks,
Nilesh
Raj VakatiRaj Vakati
Use  batch apex to query the LoginHistory which has relation with LoginGeo to get the login address 

You can schedule the batch every hour  

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_logingeo.htm
 
NM AdminNM Admin
I can see this is helpfull but how can fetch the current logged in user only?
Raj VakatiRaj Vakati
Query  AuthSession for the current user and user it in where conditions for Login Geo Object 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_authsession.htm?search_text=AuthSe
The AuthSession object represents an individual user session in your organization. This object is available in versions 29.0 and later.
NM AdminNM Admin

Thanks Raj,

AuthSession object: getting session details only.
LoginGeo: getting location from which location user logged in into the system.

I want to track the location(Latitude and Longitude) of the sales person for every hour. 
E.g.
If user started journey from A location.(Store the location from where the user started journey).
After hour check the users current location(Store the users current location).
like wise in the whole day check how much locations the sales person visited and form a map of the journey.

Any other approach?
 

Thanks,
Nilesh