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
sfdc_newbie17sfdc_newbie17 

Visualforce Javascript not executing on iphone/ipad

Hi all

I am using some code thanks to @Seth Godin to record page views which seems to work great when using the app, browser on a laptop but when users are using Safari/Chrome on their ipad or iphone these enteries ae not being recorded.

Javascript is running on my ipad and can not figure out why it's not working. Anyone have any ideas to help please?

Code below from VF page. Thanks in advance
<apex:page standardController="Account">
    <!-- variables to change for different objects -->
    <apex:variable value="{!Account.Id}"         var="RecordId" rendered="true"/>
    <apex:variable value="Account__c"            var="LookupField" rendered="true"/><!-- value = The lookup field from the audit log to the object being logged. -->
    <apex:variable value="Audit_Log__c"          var="LogObject" rendered="true"/><!-- value = The API Name of the audit log object. Only change this if you are using different audit log objects per custom object. -->
    <apex:remoteObjects >
        <apex:remoteObjectModel name="{!LogObject}" jsShorthand="cal" fields="{!LookupField},User__c" />
    </apex:remoteObjects>
    <script  type="text/javascript">
    function createUserLog() {
        // Create log record
        var contactAuditLog = new SObjectModel.{!LogObject}();
        contactAuditLog.set('<apex:outputText value="{!LookupField}" />','<apex:outputText value="{!RecordId}" />');
        contactAuditLog.set('User__c', '<apex:outputText value="{!$User.Id}" />');
        contactAuditLog.set('Operation__c', 'View'); 
        contactAuditLog.set('Object_Type__c', 'Account');
        contactAuditLog.create(function(error, result, event) {
                // Success? Exit the function.
                if(error == null) {
                    return;
                }
                // Error? Log it.
                console.log(error);
            } );
    }
    createUserLog();
    </script>
</apex:page>

 
SubratSubrat (Salesforce Developers) 
Hello ,

The code you provided looks fine, and it should work on most modern browsers, including Safari and Chrome on iPads and iPhones. However, there are a few things you can check to ensure it's working correctly on these devices:

Check JavaScript Console: Open the JavaScript console on the iPad or iPhone Safari/Chrome browser and look for any error messages or issues. You can access the console by connecting the device to a computer and using Safari's Web Inspector or Chrome Developer Tools.

Enable JavaScript: Make sure that JavaScript is enabled on the iPad or iPhone browser. Sometimes, users might accidentally disable JavaScript in their browser settings, which can prevent the script from running.

Cross-Origin Resource Sharing (CORS): If your Visualforce page is hosted on a different domain from your Salesforce instance, you might encounter CORS issues. Ensure that your server allows cross-origin requests from the domain where the Visualforce page is hosted.

Remote Objects API: Double-check if the Remote Objects API is supported on the browser versions used on iPads or iPhones. Although Remote Objects works well with modern browsers, there might be some limitations on older versions.

Clear Cache and Reload: Sometimes, caching issues can cause problems with JavaScript execution. Try clearing the cache and reloading the page to ensure you're running the latest version of the script.


If you've checked all the above points and the issue persists, it might be helpful to test the script on other iOS devices and different browser versions to see if the problem is consistent across all of them. If you find that the script is working on some iOS devices but not others, it could be related to the specific device's settings or configuration.

Hope this helps !
Thank you.