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
Ali Khan 41Ali Khan 41 

how can i get salesforce custom object's data into javascript so i can create cookies in javascript?

hi.
i am creating a custom login page using VF and Apex.. i stored the user's data who logged in through my login page in custom object. now i want to reterive custom object's data into javascript so i can create Cookies in javascript and link that javascript file into Apex code. 
So plz tell how can i reterive custom object's data from salesforce into javascript?
Raj VakatiRaj Vakati
You can use salesforce remote actions or Remote Objects in visualforce page .. please refer this link and sample code to meet your needs . Please modify your code as per the need 

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_example_simple.htm
 
<apex:page>
    
    <!-- Remote Objects definition to set accessible sObjects and fields -->
    <apex:remoteObjects >
        <apex:remoteObjectModel name="Warehouse__c" jsShorthand="Warehouse" 
            fields="Name,Id">
            <apex:remoteObjectField name="Phone__c" jsShorthand="Phone"/>
        </apex:remoteObjectModel>
    </apex:remoteObjects>

    <!-- JavaScript to make Remote Objects calls -->
    <script>
        var fetchWarehouses = function(){
            // Create a new Remote Object
            var wh = new SObjectModel.Warehouse();
            
            // Use the Remote Object to query for 10 warehouse records
            wh.retrieve({ limit: 10 }, function(err, records, event){
                if(err) {
                    alert(err.message);
                }
                else {
                     document.cookie  =records ;  
                }
            });
        };
		window.onload = fetchWarehouses;
    </script>


</apex:page>