lwc-modules
                                
                                 lwc-modules copied to clipboard
                                
                                    lwc-modules copied to clipboard
                            
                            
                            
                        Build any LWC you want without ever having to touch Apex
LWC Apex Services :fire: :zap:
A collection of LWC modules aimed at eliminating the need for writing Apex code for building LWCs, making it easier for JS devs to build components quicker on the Salesforce platform.
It contains modules for the following operations:
- 
SOQL Import soqlServiceinto your lwc and issue queries directly from your lwc!import soql from "c/soqlService"; ... this.data = await soql( "Select LastName,Account.Name,Email,Account.Owner.LastName from Contact");Refer to soqlDataTable example for details. 
- 
DML Import all exports from dmlServiceinto your lwc and useinsert,update,upsertanddeloperations as needed.import * as dml from "c/dmlService"; ... const acctId = (await dml.insert({ Name: acctName }, "Account"))[0]; //the method accepts either a single json record or json array and always returns an array of ids.For insertandupsertoperations, the sobject type must be specified as the second argument.
- 
Object and Field Describes import { describeSObjectInfo } from "c/describeMetadataService"; ... describeSObjectInfo(["Account", "Contact"]) //Get Describe information for multiple SObjects in a single call .then((resp) => { // the response has the shape of List<DescribeSObjectResult> console.log(">> got child object info ", resp); }) .catch((err) => { // handle error });import { describeFieldInfo } from "c/describeMetadataService"; ... // Retrieve field describe info for multiple fields in a single call, including relationship fields describeFieldInfo(["Account.Name","Contact.Account.Parent.Industry"]) .then(resp=>{ // the resp has the shape of List<DescribeFieldResult> })Refer to soqlDatatable for an example 
- 
Callouts via Apex (using Named Creds, if available) Call APIs that don't support CORS or require authentication, via Apex using Named Credentials. import apexCallout from "c/calloutService"; ... let contact = JSON.parse((await apexCallout("callout:random_user/api")).body); //https://randomuser.me/The full signature for this function is apexCallout(endPoint,method,headers,body).headersandbodyexpect JSON inputs
- 
Calling Salesforce APIs within your org directly from the LWC (Requires CSP Trusted Sites and CORS setup) import sfapi from "c/apiService"; ... // Calling Composite API for inserting multiple related records at once let response = await sfapi( "/composite/" /*path excluding base url*/, "POST" /*method*/, {} /* additional headers */, JSON.stringify(compositeReq) /* request body */ );Refer to compositeApiExample for the full example. 
- 
Publish Platform Events import * as platformEventService from "c/platformEventService"; ... platformEventService.publish('Test_Event__e', payload); //payload would be a json object with the shape of the Platform Event being publishedExample. 
- 
Interact with Platform Cache import * as cache from "c/platformCacheService"; ... // Add key-value pairs to cache cache.org.put(key,value); // Retrieve value from cache by key try { this.outputText = await cache.org.get(key); } catch (err) { console.error(err); }Refer to platformCacheExample for the full example. 
Considerations
- 
These modules are relatively insecure and are meant for usage in internal apps only. In other words, they are not recommended to be used for LWCs in communities or public sites. 
- 
This is still a work in progress :wrench:. Feedback and contributions welcome! :pray: