0

I was trying to play around with this nforce demo but I'm having trouble figuring out how to reference data I get back from queries. The following appears to query for info that gets displayed on the home page:

router.get('/', function(req, res, next) {

  org.query({ query: "Select Id, Name, Type, Industry, Phone, Email From Account Order By LastModifiedDate DESC" })
    .then(function(results){
      res.render('index', { records: results.records });
    });

});

Which is displayed in a table using:

{{#each records}}
<tr>
  <td>
    ...
  </td>
  <td><a href="/{{get this 'Id'}}">{{get this 'Name'}}</a> {{{badge this 'Rating'}}}</td>
  <td>{{get this 'Type'}}</td>
  <td>{{get this 'Industry'}}</td>
</tr>
{{/each}}

Why can't I change one of these td's to {{get this 'Phone'}} and have the phone number displayed? I see Phone is included in the query, but I don't understand where/if it's stored.

3

You're mis-reading the code it seems. The query for home page does NOT include Phone.

/* home page. */
router.get('/', function(req, res, next) {

  org.query({ query: "Select Id, Name, Type, Industry, Rating From Account Order By LastModifiedDate DESC" })
    .then(function(results){
      res.render('index', { records: results.records });
    });

});

It is however included in the query for record detail page (and that's probably what you mistook for home page)

/* Record detail page */
router.get('/:id', function(req, res, next) {
  // query for record, contacts and opportunities
  Promise.join(
    org.getRecord({ type: 'account', id: req.params.id }),
    org.query({ query: "Select Id, Name, Email, Title, Phone From Contact where AccountId = '" + req.params.id + "'"}),
    org.query({ query: "Select Id, Name, StageName, Amount, Probability From Opportunity where AccountId = '" + req.params.id + "'"}),
    function(account, contacts, opportunities) {
        res.render('show', { record: account, contacts: contacts.records, opps: opportunities.records });
    });
});

And you can see it's being shown on the record detail using the show.hbs template

<table class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
          <thead>
            <tr class="slds-no-hover">
              <th class="slds-text-heading--label slds-size--1-of-4" scope="col">Name</th>
              <th class="slds-text-heading--label slds-size--1-of-4" scope="col">Title</th>
              <th class="slds-text-heading--label slds-size--1-of-4" scope="col">Email</th>
              <th class="slds-text-heading--label slds-size--1-of-4" scope="col">Phone</th>
              <th class="slds-row-action" scope="col">
                <button class="slds-button slds-button--icon-border-filled slds-button--icon-border-small">
                  <svg aria-hidden="true" class="slds-button__icon slds-button__icon--hint slds-button__icon--small">
                    <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#down"></use>
                  </svg>
                  <span class="slds-assistive-text">Show More</span>
                </button>
              </th>
            </tr>
          </thead>
          <tbody>
            {{#each contacts}}
  • I've since modified the query under /* home page */ to include phone, but I'm still having the same issue. the res.render(...) is confusing me tbh – Jezza Jun 14 '16 at 23:01
  • The first argument there is the name of your hbs template - so you might be using index there for home page. For record detail, it is set to show. The 2nd argument refers to a collection of records. If you added the phone field to home page, you also need to add it to index.hbs and then it will show up. – Gaurav Kheterpal Jun 14 '16 at 23:04
0

FYI, the slightly unusual (to me anyway) syntax of e.g.:

{{get this 'Type'}}

looks like it comes from this Handlebars helper node-nforce-demo/lib/hbsHelpers.js function:

hbs.registerHelper('get', function(record, field) {
    return record.get(field);
});

so its really just a get function of an individual {{#each records}} record.

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.