Posts

Showing posts with the label GraphQL

Salesforce Fact #969 | LWC GraphQL mutation with address field

Image
While creating records with address field using GraphQL mutation feature, we need to specify each of the constituting field values of the address. For country and state, the statecode and countrycode counterparts won't work. Example error: contains a field not in 'ContactCreateRepresentation': 'MailingCountryCode' And while fetching the data, we need to specify the constituent fields as the compound field won't work. Example error: Validation error (FieldUndefined@[uiapi/ContactCreate/Record/MailingAddress/value]) : Field 'value' in type 'Contact_MailingAddress_CompoundField' is undefined Attached is the screenshot of the correct syntax.

Salesforce Fact #967 | LWC GraphQLmutation with variables

Image
We can pass variables in the mutation operations in LWC GraphQL. In this example, we are passing the LastName, Email and Phone field values as variables in the Create Contact operation. Reference:  https://developer.salesforce.com/docs/platform/lwc/guide/reference-graphql-mutation.html Attached are the screenshots.

Salesforce Fact #966 | Access fields after create record in GraphQL

Image
With the new mutation feature with GraphQL, the field values of the created record can be accessed right after the create record operation. In this example, there is an automation to set some value on the Description field and a formula field is also present on the Contact object. Both are accessible right after a record creation. Attached are the screenshots.

Salesforce Fact #965 | executeMutation in GraphQL

Image
In the upcoming Spring'26 release, we will be able to mutate data with the GraphQL api i.e. it will now be possible to perform create, update or delete operations. Also, using this api we will be able to create multiple related records in the single call, similar to composite api. In this example, we are creating an account and a related contact record. Reference:  https://developer.salesforce.com/docs/platform/graphql/guide/mutations-use.html https://developer.salesforce.com/docs/platform/lwc/guide/reference-graphql-mutation.html Attached are the screenshots.

Salesforce Fact #726 | Accessing polymorphic fields in graphQL LWC

Image
How do you access Polymorphic fields in graphQL wire adapter in LWC? Suppose we want to access the related case owner names of an account in graphQL. Since, Case Owner is a polymorphic field so we need to consider both the user and queue owner possibilities. Reference:  https://developer.salesforce.com/docs/platform/lwc/guide/reference-graphql-relationships.html Attached are the screenshots.

Salesforce Fact #723 | Related contacts in screen flow using GraphQL LWC

Image
Today let's see another use case with reactive screen components. And this time, we have the GraphQL API as well. Suppose, we have a use case where we have a lookup input on the screen flow for selecting an account record and on selecting the account, we want the related contact records(upto 10). We can create an LWC to fetch related contacts for an accountid using GraphQL API and expose the same in the screen flow. Attached are the screenshots.

Salesforce Fact #698 | Aggregate functions in graphql

Image
We can use aggregate functions as well with graphql wire adapter.  In this example, we are getting the related Contact and Opportunity count for an account using the ' totalCount ' variable. Reference:  https://developer.salesforce.com/docs/platform/graphql/guide/aggregate-examples.html Attached is the screenshot.

Salesforce Fact #697 | Getting related contacts using graphql

Image
How do you pass dynamic value for the parameter in graphql query. The values need to be passed in the ' variables ' parameter and the return value is accessed through a getter function. In this example, we are getting the related contacts passing the accountId from the account record detail page. Reference:  https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_graphql Attached is the screenshot.

Salesforce Fact #696 | GraphQL wire adapter in LWC

Image
With Summer'23 release, the GraphQL wire adapter can be used in LWC and it makes use of LDS. In this example, we are fetching the account records with non-empty Rating and Type value. Note: The result contains 10 records. Reference:  https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_graphql Attached are the screenshots.