Skip to main content
Mohankumar B 님이 #Data Management에 질문했습니다
Hi,

 

Not getting exact current location (latitude and longtitude) in this below trigger.Can anyhelp me for this one.

 

Trigger:

 

 

trigger ActivityLocation on Activity_Master__c (Before insert,before Update) {

 

    LoginGeo loggedInUserGeo;

 

    LoginHistory loggedInUserHistory = [SELECT id,SourceIp ,LoginTime,LoginGeoId  FROM LoginHistory WHERE userId =: userInfo.getUserId() order by LoginTime desc limit 1];

 

    if(loggedInUserHistory != NULL)

 

        loggedInUserGeo = [SELECT Id,Latitude, Longitude from LoginGeo WHERE Id =: loggedInUserHistory.LoginGeoId];

 

    if(Trigger.isInsert || Trigger.isUpdate){

 

        for(Activity_Master__c AM : Trigger.new){

 

            AM.Location_Activity__Latitude__s = loggedInUserGeo.Latitude;

 

            AM.Location_Activity__Longitude__s = loggedInUserGeo.Longitude;

 

        }    

 

    }

 

}

 

 
답변 2개
  1. 2020년 7월 17일 오전 6:02
    Hi, 

     

    The location indicated in the login history is based on the user's IP address and, as such, will never be accurate.

     

    If you want to know where the user actually is, you will need to build a page or component that uses Javascript to request the user's location with the geolocation API. Note that users can reject this kind of request and you may end up with no location at all. 
0/9000