SFDX Create Apex Class

SFDX: Create Apex Class
— Salesforce CLI

12:14:32.9 sfdx force:apex:class:create 
--classname ContactController 
--template DefaultApexClass 
--outputdir force-app/main/default/classes 
ended with exit code 0
// Aura Enabled Apex Method (Apex)

@AuraEnabled
/* * * AuraEnabled Annotation?
* * The @auraEnabled annotation enables client-and server-side access to an Apex controller methos. 
Providing this annotation makes your methos available to your lightning components (both Lightning web components and Aura components). 
Only methods with this annotation are exposed.
* * This API version 44.0 and later, you can improve runtime performance by caching method results on the client by using the annotation 
* * @AuraEnabled(cacheable=true). You can cach method results only for aliminates 
the need to call setStorable() in javaScript code on every action that calls the Apex methos.

* * https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_AuraEnabled.htm
*/

public static string methodName(){

}

///---accountId each value getRelatedContacts is List
public with sharing class ContactController {
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> getRelatedContacts(Id accountId){
        return [select Id, Name, Phone, Email from Contact where AccountId=:accountId];
    }
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> getRelatedContactByFilter(Id accountId,String key){
        String query='select Id, Name, Phone, Email from Contact where AccountId=:accountId AND NAME LIKE \'%'+KEY+'%\'';
        return Database.query(query);
    }
}

Tracked Properties

To track a private property’s value and rerender a component when it changes, decorate the property with @track. Tracked properties are also called private reactive properties.

You can use a tracked property directly in a template. You can also a tracked property indirectly in a getter of a property that’s used in a template.

Both @track and @api mark a property as reactive. If the property’s value changes, the component re-renders. Tracked properties are private, where properties decorated with @api are public and can be set bu another component.

NOTE: Don’t overuse @track. Track a property only if you need the component to rerender when the property’s value changes.

@track private
@api public

import { LightningElement, track } from 'lwc';