0

I have a custom button on task object, and it will open a visualforce page that contains google maps and check in button. If user click check in button, it will update Actual_CheckIn field on task. It work fine for almost a year, but since Monday, the user cannot check in using that visualforce again thru salesforce1 (mobile) .. it showed error

Error:{errors:{fields:'id',message:'Activity ID: id value of incorrect type: undefined',statusCode:'MALFORMED_ID',}, id:null,success:'false',}

I tried to check in using web interface, and it works fine, but error if using mobile apps.

enter image description here

This is the custom button : enter image description here

this is the visualforce code :

<apex:page docType="html-5.0" standardStylesheets="false" sidebar="false" cache="false" showHeader="false">
    <head> 
        <title>Check-In</title>
        <apex:includeScript value="{!URLFOR($Resource.SDO_jqueryui192, '/js/jquery-1.8.3.js')}"/>
        <apex:includeScript value="{!URLFOR($Resource.MobileSample_Resources_jQueryMobile, 'ForceTk.js')}"/>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={!$Label.GapiKey}&sensor=true&libraries=places"></script>
        <!--<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script>-->
        <!--<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>-->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css"/>
        <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
        <apex:includeScript value="/soap/ajax/33.0/connection.js"/>
        <apex:includeScript value="/soap/ajax/33.0/apex.js"/>

        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

        <script type="text/javascript">
            function InitializeMap(position) {               
                var mapOptions = {
                    zoom: 15,
                    center: new google.maps.LatLng(-34.398, 150.644),
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                geocoder = new google.maps.Geocoder();
                //infowindow = new google.maps.InfoWindow;
            }

            function captureLocation() {
                deleteOverlays();
                if(navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(function(position) {
                        pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                        addMarkerWithIcon(pos, '', true, null, false);                        
                        map.setCenter(pos);
                        google.maps.event.trigger(map, "resize");
                        var inputs = document.getElementsByTagName('input');
                        for(var x = 0; x < inputs.length; x++) {
                            if(inputs[x].id.indexOf('maplat') >= 0) { inputs[x].value = position.coords.latitude; }
                            if(inputs[x].id.indexOf('maplong') >= 0) { inputs[x].value = position.coords.longitude; }
                        }
                        geocodeLatLng();
                    });
                }else{
                    alert("Your browser doesn't support the Geolocation API");
                }
            }

            function geocodeLatLng() {
              //var input = document.getElementById('latlng').value;
              //var latlngStr = input.split(',', 2);

              var getlat = document.getElementById('maplat').value;
              var getlong = document.getElementById('maplong').value;
              geocoder = new google.maps.Geocoder();
              var latlng = {lat: parseFloat(getlat), lng: parseFloat(getlong)};
              geocoder.geocode({'location': latlng}, function(results, status) {
                if (status === google.maps.GeocoderStatus.OK) {
                  if (results[1]) {
                    //map.setZoom(15);
                    //var marker = new google.maps.Marker({
                    //  position: latlng,
                    //  map: map
                    //});
                    //infowindow.setContent(results[1].formatted_address);
                    //infowindow.open(map, marker);
                    document.getElementById("address").value = results[1].formatted_address;
                  } else {
                    window.alert('No results found');
                  }
                } else {
                  window.alert('Geocoder failed due to: ' + status);
                }
              });
            }

            function findNearbyAccounts() {
                var soql = "Select Id, Name From Account Where Show_on_Checkin_Map__c = true Limit 5";
                client.query(soql, function(data) {
                    if(data.totalSize > 0) {
                        nearbyAccounts = data.records;
                        setTimeout('placeAccountsOnMap()',200);
                    }
                });
            }

            function placeAccountsOnMap() {
                var request = {
                    location: pos,
                    radius: 300,
                    types: ['store']
                };

                var service = new google.maps.places.PlacesService(map);
                service.nearbySearch(request, accountcallback);
            }

            function accountcallback(results, status) {
                if (status == google.maps.places.PlacesServiceStatus.OK) {
                    for (var i = 0; i < nearbyAccounts.length && i < results.length; i++) {
                        console.log(nearbyAccounts[i]);
                        addAccountWithIcon(results[i].geometry.location, null, false, nearbyAccounts[i]);
                    }
                }
            }

            function findNearbyUsers() {
                var soql = "Select Id, Name, SmallPhotoURL, Phone From User Where Show_on_Checkin_Map__c = true Limit 5";
                client.query(soql, function(data) {
                    if(data.totalSize > 0) {
                        nearbyUsers = data.records;
                        setTimeout('placeUsersOnMap()',200);
                    }
                });
            }

            function placeUsersOnMap() {
                var request = {
                    location: pos,
                    radius: 300,
                    types: ['atm']
                };

                var service = new google.maps.places.PlacesService(map);
                service.nearbySearch(request, usercallback);
            }

            function usercallback(results, status) {
                if (status == google.maps.places.PlacesServiceStatus.OK) {
                    for (var i = 0; i < nearbyUsers.length && i < results.length; i++) {
                        addMarkerWithIcon(results[i].geometry.location, nearbyUsers[i].SmallPhotoUrl, false, nearbyUsers[i], true);
                    }
                }
            }

            function addMarkerToMap(location) {
                var marker = new google.maps.Marker({ 
                    map: map, 
                    position: location,
                    animation: google.maps.Animation.DROP
                });
                markers.push(marker);
            }

            function addAccountWithIcon(point, imgURL, drag, v) {
                if(v) {
                    var contentString = '<div id="content">' +
                            '<table>' +
                                '<tbody>' +
                                    '<tr><td><b>' + v.Name + '</b></td></tr>' +
                                '</tbody>' +
                            '</table>' +
                        '</div>';
                }

                var img = '/resource/map_account';

                var marker = new google.maps.Marker({
                    position: point,
                    animation: google.maps.Animation.DROP,
                    map: map,
                    draggable: drag,
                    icon: img
                });
                markers.push(marker);

                if(v) {
                    var infowindow = new google.maps.InfoWindow({ 
                        content: contentString 
                    });          
                    google.maps.event.addListener(marker, 'click', function() { 
                        infowindow.open(map,marker); 
                    });
                }
            }

            function addMarkerWithIcon(point, imgURL, drag, v, ic) {
                if(v) {
                    var contentString = '<div id="mcontent">' +
                            '<table>' +
                                '<tbody>' +
                                    '<tr><td><img src="' + v.SmallPhotoUrl + '" alt=""/></td>' +
                                    '<td><b>' + v.Name + '</b><br/>' + v.Phone + '<br/>4 minutes ago</td></tr>' +
                                    '<tr><td colspan="2">Onsite at the customer.</td></tr>' +
                                '</tbody>' +
                            '</table>' +
                        '</div>';
                }

                var marker;

                if(ic) {    
                    var img = '/resource/map_coworker';

                    marker = new google.maps.Marker({
                        position: point,
                        animation: google.maps.Animation.DROP,
                        map: map,
                        draggable: drag,
                        icon: img
                    });
                } else {
                    marker = new google.maps.Marker({
                        position: point,
                        animation: google.maps.Animation.DROP,
                        map: map,
                        draggable: drag
                    });
                }
                markers.push(marker);

                if(v) {
                    var infowindow = new google.maps.InfoWindow({ 
                        content: contentString 
                    });          
                    google.maps.event.addListener(marker, 'click', function() { 
                        infowindow.open(map,marker); 
                    });
                }
            }

            function setMarkerMap(map) {
                for (var i = 0; i < markers.length; i++)
                    markers[i].setMap(map);
            }

            function clearOverlays() {
                setMarkerMap(null);
            }

            function deleteOverlays() {
                clearOverlays();
                markers = [];
            }

            $(document).ready(function() {  
                console.log("CheckIn Ready...");
                client = new forcetk.Client();
                client.setSessionToken('{!$API.Session_ID}'); 
                InitializeMap();
                setTimeout('captureLocation()',300);
                Initial_Event();
            });

            var client, map, pos;
            var nearbyUsers, nearbyAccounts;
            var markers = [];

            function Check_in(){
                try{
                    var url = window.location.href;
                    var captured = /id=([^&]+)/.exec(url)[1];
                    var result = captured ? captured : 'error';  

                    var lat = document.getElementById('maplat').value;
                    var long = document.getElementById('maplong').value;
                    var today = new Date();
                    var address = document.getElementById('address').value;

                    sforce.connection.sessionId = "{!$Api.Session_ID}";
                    var o = new sforce.SObject("Task");
                    o.id = result; 
                    o.Location_Latitude__c = lat;
                    o.Location_Longitude__c = long;
                    o.Actual_Check_In__c = today;
                    o.Check_In_Address__c = address;

                    try{
                        var result1 = sforce.connection.update([o]);
                        if(result1[0].getBoolean("success"))
                        {
                           alert('Check-In successfully');
                           //window.opener.location.href="/{!$CurrentPage.parameters.id}";
                           window.close();

                        }
                        else{
                          alert('Error : '+result1);
                        }
                    }

                    catch(err){
                        alert(err);
                    }
                }catch(err){
                    alert('Check-In error.');
                } 
            }

            function Initial_Event(){
                try{
                    var url = window.location.href;
                    var captured = /id=([^&]+)/.exec(url)[1];
                    var result = captured ? captured : 'error';

                    if(result == 'error'){
                        alert('Event tidak terdaftar.');
                    }else{
                        var soql = "Select Subject From Task Where Id = '" + result + "'";
                        client.query(soql, function(data) {
                            if(data.totalSize > 0) {
                                document.getElementById('Subject').innerHTML = data.records[0].Subject;
                            }
                        });
                    }
                }catch(err){
                    alert('Check-In error.');
                }        
            }

        </script>

        <style type="text/css">
            .mapArea {
                width: 100%;
            }

            #map-canvas {
                margin: 5px;
                padding: 0;
                min-height: 250px;
            }

            @media (min-width: 400px) { 
                #map-canvas {
                    margin: 5px;
                    padding: 0;
                    min-height: 350px;
                    height: 100%;
                }
            }          

            #wrap {
              min-height: 100%;
              height: auto !important;
              height: 100%;
              margin: 0 auto -60px;
              padding: 0 0 60px;
            }

            .btnA {
                width: 100%;
                border-radius: 0px;
            } 

            body {
                padding-left: 15px;
                padding-right: 15px;
            } 

            .col-xs-4, .col-lg-12, .col-xs-12, .col-xs-6 {
                padding-left: 0px;
                padding-right: 0px;
            }         
        </style>
    </head>

    <body>
        <apex:form >
        <div class="container">
            <div class="row">
                <div class="col-lg-12 col-xs-12">
                    <div class="form-group">
                        <label class="control-label">Event Name</label><br/>
                        <div id="Subject" />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12 col-lg-12">
                    <div class="mapArea">
                        <div id="map-canvas"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <button type="button" class="btnA btn-default" onClick="javascript:captureLocation()">Me</button>
                </div> 
                <div class="col-xs-6">
                    <button type="button" class="btnA btn-default" onClick="javascript:Check_in()">Check In</button>
                </div>

            </div>
            <div class="row">
                <input type="text" id="maplat" style="visibility:hidden;"/>
                <input type="text" id="maplong" style="visibility:hidden;"/>
                <input type="text" id="address" style="visibility:hidden;"/>
            </div>
        </div>
        <apex:message />
        </apex:form>
    </body>
</apex:page>
2
  • 1
    So it looks like your error is in the function Check_In(). Can you capture debug information for what's happening there? What is the value of window.location.href when it fails, for example?
    – David Reed
    Jun 11, 2019 at 11:49
  • Hi @DavidReed, I`ll update this comment after I do debug. Because currently I dont have permission to open dev console and debug menu. The user gave me wrong user with != sysadmin profile Jun 13, 2019 at 2:58

1 Answer 1

0

Phew my user just gave me the correct user for me to debug Today. My bad.

I just realized that this VF want to get the task ID without using standardController, so I added standardController="Task" and capture the task ID :

                var url = window.location.href;
                var captured = /id=([^&]+)/.exec(url)[1];
                var cek = captured.substring(0, 3);
                if(cek!="00T"){
                    captured = "{!task.id}";  
                }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .