1

I am trying to update the Custom Setting using remote Object in visualforce page, the scenario is when every time on load of the page I want to update the sessionId in custom setting, but using remote object I am not able to do that,

Here is my code of vf page which is not working on update

 <!-- defining custom setting here -->
<apex:remoteObjects jsNamespace="RemoteObjectModel">  
    <apex:remoteObjectModel name="Config__c" fields="Id,PartnerUrl__c,SessionId__c">  
    </apex:remoteObjectModel>  
</apex:remoteObjects> 

<script>


    //to save data in custom setting 
    function remot() { 

            var ct = new RemoteObjectModel.Config__c({   
            PartnerUrl__c: '{!$Api.Partner_Server_URL_310}', 
            SessionId__c: '{!$API.Session_Id}',   

        });  
        ct.update();  
    }  

    remot();

</script>
2
  • what is your use case, what are you trying to achieve storing sessionId in custom settings? May 12, 2017 at 20:12
  • 1
    Why are you trying to store session ids in a custom setting? It is already stored elsewhere in the system...
    – Adrian Larson
    May 12, 2017 at 20:15

1 Answer 1

2

You forgot to include the record Id. Without a record Id you can't perform an update. Depending on your custom setting, the following should probably work:

(new RemoteObjectModel.Config__c()).retrieve(
    { where: { SetupOwnerId: { eq: "{!$User.Id}") } } }, function(error, records, event) {
    if(records[0]) {
        (new RemoteObjectModel.Config__c({
            PartnerUrl__c: '{!$Api.Partner_Server_URL_310}', 
            SessionId__c: '{!$API.Session_Id}',
            Id: records[0].get("Id")
        })).update();
    } else {
        (new RemoteObjectModel.Config__c({
            PartnerUrl__c: '{!$Api.Partner_Server_URL_310}', 
            SessionId__c: '{!$API.Session_Id}'
        })).create();
    }
});

See Using Remote Objects in JavaScript and its related sub-topics.

0

You must log in to answer this question.

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