I am trying to fetch multiple picklists to show on LWC components. I am seeing many examples to do this using getPicklistValuesByRecordType from 'lightning/uiObjectInfoApi' and few examples by calling the Apex class and getting this data. I am trying to understand what is best way and pros and cons of these two approaches. I am new to salesforce and my teammates said they never used 'lightning/uiObjectInfoApi' and not ready to accept my solution using this. Please provide some insights here, Thanks.
1 Answer
As far as I'm aware, there are no pros to using Apex over the REST API. Apex itself has to describe the metadata, which has a small, but appreciable cost, then loading the appropriate data structures before finally returning the data, including extra steps for serializing and deserializing JSON. By cutting Apex out of the process, your component's data will load faster and use fewer resources overall. In LWC, using the wire resources are almost always faster, the single exception being when you need to perform bulk actions (e.g. createRecord
to create multiple records is slower than Apex after about 5-10 records).
-
1Also, if going with apex, you will need to spend time on unit tests Feb 10 at 18:14
-