1. import apexMethod
//js
import updateRecord from "@salesforce/apex/freeTestLwcCmp.updateRecord";
2. JSON 형식으로 전달할 매개변수 값 세팅
//js
let updateData = {
recordId : this.recordId,
templateStatus : '사용가능',
mainObjLabel : '계약',
mainObjApi : 'Contract',
};
3. 메서드 호출시 매개변수 값 전달 - JSON.stringify()
//js
updateRecord({updateData : JSON.stringify(updateData)})
.then(result => { }).catch(error => { })
4. Apex 클래스에서 내부 모델 클래스 활용하여 값 활용하기
//apex class
public with sharing class freeTestLwcCmp {
public freeTestLwcCmp() {}
//1. 활용할 내부 Model Class 생성
public class Model_FM_MasterForm{
@AuraEnabled public String recordId{get;set;}
@AuraEnabled public String mainObjLabel{get;set;}
@AuraEnabled public String mainObjApi{get;set;}
@AuraEnabled public String templateStatus {get;set;}
public Model_FM_MasterForm(){}
public Model_FM_MasterForm(Map<String,Object> m){
if(m.containsKey('recordId')){
this.recordId = String.valueOf(m.get('recordId')??'');
}
}
}
//2. 전달받은 JSON String값 활용 - JSON.deserialize()
@AuraEnabled
public static String updateRecord(String updateData){
Model_FM_MasterForm data =
(Model_FM_MasterForm)JSON.deserialize(updateData, Model_FM_MasterForm.class);
//data.templateStatus 형식으로 활용
}
}