Skip to main content

Add a Tile for Each Contact

What You’ll Do

  • Fetch a list of contacts from your org
  • Display each one using a tile component

Step 1: Add Contact Tiles

Now that we have the basic page setup, we're going to fetch a list of contacts and append each contact as a tile to the “contact-list” div.

We’ll be using Visualforce remote objects for data access, accessed via JavaScript.

Modify the code base by adding the following code between the <!-- JAVASCRIPT --> comments:

<!-- JAVASCRIPT --> <script> (function () { var contact = new SObjectModel.Contact(); var contactList = document.getElementById('contact-list'); /* FUNCTION createTile */ function createTile(record) { return ['<li class="slds-item">', '<div class="slds-tile slds-media">', '<div class="slds-media__body">', '<h3 class="slds-truncate" title="', record.get('Name'), '"><a href="javascript:void(0);">', record.get('Name'), '</a></h3>', '<div class="slds-tile__detail slds-text-body_small">', '<p class="slds-truncate">', record.get( 'Title'), '</p>', '</div>', '</div>', '</div>', '</li>' ].join(''); } /* FUNCTION createTile */ contact.retrieve({ orderby: [{ LastModifiedDate: 'DESC' }], limit: 810 }, function (error, records) { if (error) { alert(error.message); } else { contactList.innerHTML = records.map(createTile).join(''); } }); })(); </script> <!-- JAVASCRIPT -->

Step 2: Preview

Save your page, and click the Preview button.

Preview of Visualforce page after adding tiles for contacts

Resources

The Lightning Design System site has more documentation and examples for the components used above.

계속해서 무료로 학습하세요!
계속 진행하려면 계정을 가입하세요.
얻을 수 있는 이점
  • 커리어 목표에 대한 개인화된 권장 사항 제공받기
  • 실습 과제 및 퀴즈를 통해 스킬 연습
  • 진행 상황을 추적하고 고용주에게 공유
  • 멘토십과 커리어 기회에 연결