0

I have a LWC component, I want to get data of page-layout assigned to user's profile and the fields in the layout. For custom profiles they won't have 'View setup' permission which is needed to get the page layout details assigned to user's profile. So I'm assigning permission set dynamically to the user by creating permissionSetAssignment dynamically and then getting profile's page layout.

So, assigning of PS should be done 1st and then query for page layout and its process should done. And that fields data from page layout should be cached. I called method for assigning PS from connected callback and method from wire which gets the page layout fields. But calls to method are inconsistent and the working also made inconsistent.

Is there any way to make the process synchronous but the data should be cached (which used in offline in FSL mobile app).

@wire(getFieldsData, {
    objectApiName: '$quickActionObjectName',
    recordId: '$recordId'
})
wiredGetFieldsData({ error, data }) {
    if (data) {
        this.handleSectionsFields(data);
        //After fetching the data, calling the remove permission set method
        this.callRemovePermissionSet();
    } else if (error) {
        console.error(error);
        //Incase any error while fetching the data, calling the remove permission set method
        this.callRemovePermissionSet();
    }
}

connectedCallback() {
    createPermissionSet().then(response=>{

    }).catch((error) =>{
        console.error('Error create permission set:', error);
    })
}

Thank you!

2
  • Please add sample LWC Code so we can see the order and if you are using async correctly.
    – metasync
    Dec 5, 2023 at 16:04
  • @metasync, I have updated the question with code Dec 5, 2023 at 16:30

1 Answer 1

0

Basically you have to wait till first apex method returns a result, to call second method from your LWC

You can achieve this 3 ways:

  1. Use async await
  2. Using .then method
  3. Use promises

With the minimum information this is all i can say, please share lwc and apex code to comment more on this. But you can surely check the approach and try from your end mean time.

3
  • Yes, it will work. But the data should be cached, so that FSL mobile app uses it. I didn't mention about the FSL app previously in the question. Now I have updated it. Thanks! Dec 5, 2023 at 16:35
  • If you are calling createPermissionSet() from connected call back, it will load every time the component is inserted to the dom. Is this something you are expecting? Dec 5, 2023 at 16:42
  • Yes, if the device is online then it should call every time. If offline just needed to show cached data (so wire is using) Dec 5, 2023 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .