1

So I am working to create a VF page that pulls a list of records from a custom object (Individual_Account__c) and I am also trying to filter this list of records based on a cross-object formula field (Current_Year__c) which is a checkbox. I only want the list to pull records that are "true". Here is the code I have:

<apex:remoteObjects >
<apex:remoteObjectModel name="Individual_Account__c" fields="Id,Name,LastModifiedDate,Current_Year__c"/>
</apex:remoteObjects>

<div class="mypage">
<h2>Individual Accounts</h2>
<ul id="accountList"/>
</div>    

<script>
var ul = document.getElementById("accountList");
var account = new SObjectModel.Individual_Account__c();
account.retrieve(
{where: { 
    Current_Year__c: {eq: 'true'}}
},
{orderby: [{LastModifiedDate: 'DESC'}], limit: 15}, 
function(error, records) {
    if (error) {
        alert(error.message);
    } else {
        var html = "";
        records.forEach(function(record) {
            html = html + "<li><a data-id=" + record.get("Id") + ">" + 
                           record.get("Name") + "</a></li>";
        });
        ul.innerHTML = html;
    }
}
);

ul.addEventListener("click", function(e) {
sforce.one.navigateToSObject(e.target.getAttribute("data-id"));
});

</script>

</apex:page>

Everything works with this code except for when I insert this line:

{where: { 
    Current_Year__c: {eq: 'true'}}},

Any idea what the issue?

Thanks!

2

Remove the quotes around true. With it like that you are checking for a string value and not a boolean value.

After talking with the OP and getting more detail into his problem the solution is:

<apex:remoteObjects >
    <apex:remoteObjectModel name="Individual_Account__c" fields="Id,Name,LastModifiedDate,Current_Year__c"/>
</apex:remoteObjects>
<script>
var account = new SObjectModel.Individual_Account__c();

account.retrieve({where: {Current_Year__c: {eq: true}}, orderby: [{LastModifiedDate: 'DESC'}], limit: 15}, function(error, records) {
  if (error) {
    alert(error.message);
  } else {
    records.forEach(function(record) {
      console.log(record.get('Name'));
      console.log(record.get('Current_Year__c'));
    });
  }
});

There are a few places with caveats if you have a namespace on your org.

First is making the custom object:

var account = new SObjectModel.NamespaceNeeded__Individual_Account__c();

Next is querying custom fields:

... {where: {NamespaceNeeded__Current_Year__c: {eq: true}}} ...

And getting the custom fields:

console.log(record.get('NamespaceNeeded__Current_Year__c'));

I cleaned out the original code to only show what is needed to make it work.

| improve this answer | |
  • 1
    I am looking at some code I have that works that is nearly identical. Except I have the where clause after my orderbys. I wouldn't think that would matter, but try it maybe? I can paste a snippet in the answer (temporarily) if you would like. – Jesse Milburn Mar 23 '16 at 18:19
  • in that snippet your {}'s are not balanced. I'm gonna set up a room, if you have time? chat.stackexchange.com/rooms/37407/helping-ryan – Jesse Milburn Mar 23 '16 at 18:28
  • Thanks for continuing to look at this Jesse. I've put your new code in and nothing is being displayed on the page itself but the console is returning the appropriate records, they just aren't making it to the page itself. – Ryan Bowen Mar 24 '16 at 14:43
  • 1
    @RyanBowen that is intended. I just got the query to work. you need to write the html. If it is giving you what you needed please mark as answered. Good luck. – Jesse Milburn Mar 24 '16 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.