Sales Visit Name:

Sales Visit Description:

Longitude:

Latitude:

After that include Sales Visit in a new Salesforce tab: to do so, go to Setup> Create> Tabs> New. Then, select Sales_Visit as the Visualforce Page. Enter Sales Visit as the tab label. Then, make sure to mark \"Mobile Ready\" to enable this tab in mobile mode. And now, whenever a new record is saved in Sales Visit, the location of the user is captured along with it. Note that you must set all users’ phones to allow recording of the GPS location for the browser. Please let us know if you are looking for something else. Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it. Best Regards, Nagendra.P  ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T41NiSAJ", "datePublished": "2016-11-02T11:59:14.000Z", "author": { "@type": "Person", "name": "Nagendra Babu Pilli", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CO9yeQAD", "affiliation": { "@type": "Organization", "name": "Salesforce" } } } ] } }
Skip to main content
답변 4개
  1. 2016년 11월 2일 오전 11:59
    Hi Vishwanath,

    In some scenarios, organizations where, data collection is important, capturing the location of where the users are entering new information can be helpful.In this article it's explained,  how you can allow Salesforce to log the users' location when, for example, a new record is saved in a sales visit. 

    To do that, we're going to create a new tab (Sales Visit) that contains a Visualforce page. The Visualforce page will then capture the location of the users when they save a new record. 

    First, let's create the object Sales Visit:

    Go to Setup> Create> Objects> New Custom Object and put "Sales Visit" as the label of the object.

    Then, we're going to create three custom fields:

    • Description: choose Text Area as data type. 
    • Longitude: Choose Number as the data type. Enter 3 as the length and 10 as the Decimal Places. After you hit save, create Latitude with the same data type, length, and decimal places. 
    Second, create an Apex Class (which performs like the Sales Visit but with a slightly different behavior):

    The difference of behavior for the Apex Class is that normally when you save a new record, the record's detail page is displayed. Because we don't want to overload the phone's small screen with unnecessary information, we're going to replace the record's detail page with a blank Sales Visit record instead.

    Go to Setup> Develop> Apex Classes> New and then enter in the following code then hit Save:

    public class visitController {

    public Sales_Visit_c visit__c();}

    public visitController() {

    visit = new Sales_Visit__c();

    }

    public PageReference save() {

    insert visit;

    visit = new Sales_Visit__c();

    return null;

    }

    }

    Third,Create a Visualforce page that captures and sends the GPS co-ordinates of when the sales visit record is saved:

    Go to Setup> Develop> Pages> New

    Enter Sales Visit Form as the label and name.

    Delete the markup that gets automatically created with the following code:

    <apex:page controller="visitController" showHeader="false"

    sidebar="false" setup="true" standardStylesheets="false"

    >

    <head>

    <meta content="width = device-width"/>

    <script

    src="/mobileclient/api/mobileforce.js"></script>

    <script>

    function updateLocation(lat,lon) {

    document.getElementById(

    '{!$Component.form.block.longitude}').value=lon;

    document.getElementById(

    '{!$Component.form.block.latitude}').value=lat;

    }

    function getLocation() {

    mobileforce.device.getLocation(updateLocation);

    //work around required for BB

    if (window.blackberry)

    setInterval("getLocation()", 10000);

    return false;

    }

    </script>

    </head>

    <apex:form>

    <apex:pageBlock>

    Sales Visit Name: <br />

    <apex:inputField value="{!visit.name}" /><br />

    Sales Visit Description: <br />

    <apex:inputField value="{!visit.Description__c}" /><br />

    Longitude: <br />

    <apex:inputField value="{!visit.Longitude__c}"

    /><br />

    Latitude: <br />

    <apex:inputField value="{!visit.Latitude__c}"

    /><br />

    <button value="GPS"

    onclick="getLocation();"> Get location </button>

    <apex:commandButton action="{!save}" value="Save!" />

    </apex:pageBlock>

    </apex:form>

    After that include Sales Visit in a new Salesforce tab:

    to do so, go to Setup> Create> Tabs> New. Then, select Sales_Visit as the Visualforce Page. Enter Sales Visit as the tab label. Then, make sure to mark "Mobile Ready" to enable this tab in mobile mode.

    And now, whenever a new record is saved in Sales Visit, the location of the user is captured along with it. Note that you must set all users’ phones to allow recording of the GPS location for the browser.

    Please let us know if you are looking for something else.

    Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.

    Best Regards,

    Nagendra.P

     
0/9000