Newer Version Available

This content describes an older version of this product. View Latest

AppReviewService Example

Here’s a minimal but complete example of a Lightning web component that uses AppReviewService to request an app review.

The component’s HTML template contains a button to request an app review.

1<!-- appReviewFeedbackServiceExample.html -->
2<template>
3    <lightning-card title="App Review Feedback" icon-name="custom:custom14">
4        <div class="slds-var-m-around_medium">
5            <div>Hello, {name}!</div>
6            <div class="slds-var-m-top_x-small">
7                <lightning-button label="Request App Review" value="Action" onclick={handleBeginClick}></lightning-button>
8            </div>
9        </div>
10    </lightning-card>
11</template>

Each phase of the app review request writes a console message.

1// appReviewServiceExample.js
2import { LightningElement, wire } from 'lwc';
3import { getAppReviewService } from 'lightning/mobileCapabilities';
4import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
5import Id from '@salesforce/user/Id';
6import NAME_FIELD from '@salesforce/schema/User.Name';
7const fields = [NAME_FIELD];
8const userName = getFieldValue(this.user.data, NAME_FIELD)
9
10export default class AppReviewFeedbackService extends LightningElement {
11    userId = Id;
12    user;
13
14    @wire(getRecord, { recordId: '$userId', fields })
15    user;
16
17    get name() {
18        return userName || "Guest User";
19    }
20
21    handleBeginClick(event) {
22        const myAppReviewService = getAppReviewService();
23        if (myAppReviewService.isAvailable()) {
24            myAppReviewService.requestAppReview(null)
25                .then(() => {
26                    // Do something with success response
27                    console.log("App review request complete successfully");
28                })
29                .catch((error) => {
30                    // Handle cancellation and scanning errors here
31                    console.error(error);
32                });
33        }
34        else {
35            // Handle with message, error, beep, and so on
36            console.error("App Review service not available");
37        }
38    }
39}