Skip to content

ProjectMulti-language LWCs on the GraphQL API

  • Industry

    Cross-industry

  • Cloud

    Lightning Web Components, OmniStudio

  • Role

    LWC developer

  • Period

    Independent, 2023 – present

Problem

Users in several languages need the same component, and the component needs data from several objects without a chain of Apex methods or a request per object.

What I built

LWCs that are translatable and read their data through the GraphQL API, with FlexCards and integrations embedded inside them.

How it works

The pattern: translatable by design. User-facing text is never hard-coded in the template, so the component can follow the user’s language without a code change. Dates and numbers go through the platform’s locale-aware formatting rather than being hand-formatted.

One query, exactly the fields. The GraphQL API fetches a record and its related records in a single request and returns only the fields asked for. In LWC, the graphql wire adapter takes the query and its variables as reactive inputs, so the component refetches when they change.

Embedded OmniStudio. FlexCards and Integration Procedures can be placed inside the LWC, so a custom shell hosts OmniStudio-built pieces where that is the quicker route.

Illustrative: rebuilt for this site, not client codecaseSummary.js
import { LightningElement, api, wire } from 'lwc';
import { gql, graphql } from 'lightning/uiGraphQLApi';
import LABEL_TITLE from '@salesforce/label/c.Case_Summary_Title';
import LABEL_EMPTY from '@salesforce/label/c.Case_Summary_Empty';

export default class CaseSummary extends LightningElement {
  @api recordId;
  labels = { title: LABEL_TITLE, empty: LABEL_EMPTY };
  cases = [];

  @wire(graphql, {
      query: gql`
          query casesForAccount($accountId: ID) {
              uiapi {
                  query {
                      Case(where: { AccountId: { eq: $accountId } }, first: 10) {
                          edges { node { Id Subject { value } Status { value displayValue } } }
                      }
                  }
              }
          }`,
      variables: '$variables',
  })
  result({ data }) {
      if (data) {
          this.cases = data.uiapi.query.Case.edges.map(({ node }) => ({
              id: node.Id, subject: node.Subject.value, status: node.Status.displayValue,
          }));
      }
  }

  get variables() { return { accountId: this.recordId }; }
  get isEmpty() { return this.cases.length === 0; }
}

Built with the Salesforce Lightning Design System. Not affiliated with Salesforce.

App Launcher