I'm creating a custom lead conversion page, I'm trying to pass the lead to an apex controller, I think the problem I guess is when the 'handleConvert' function in js is called, the variable varLeadRecord is not recognized by the apex.
Here is my js controller:
import { LightningElement, api, wire, track } from 'lwc';
import getLeadRecord from '@salesforce/apex/apexController.getLeadRecord';
import convertLead from '@salesforce/apex/apexController.convertLead';
export default class CustomLeadConversion extends LightningElement {
@api recordId;
@track isNewAccount = true;
@track isNewContact = true;
@track isNewOpp = true;
@track varLeadRecord = {};
@wire(getLeadRecord, { leadId : '$recordId' })
leadRecordDetails({ data, error }){
if(data){
this.varLeadRecord = data;
console.log('this.varLeadRecord please');
console.log(this.varLeadRecord);
console.log(this.varLeadRecord.Name);
console.log(this.varLeadRecord.Id);
}else if(error){
}
}
handleConvert(){
console.log('convert button is clicked'); //this is OK
console.log(this.varLeadRecord); //
convertLead({leadRec: '$this.varLeadRecord'})
.then(result => {
console.log(result);
})
.catch(error => {
this.error = error;
});
}
}
Here is my APEX controller
public class apexController{
@AuraEnabled(cacheable=true)
public static Lead getLeadRecord(String leadId) {
System.debug('leadId ' + leadId);
Lead leadRec;
List<Lead> leadList = [SELECT Id, Name, Salutation, FirstName, LastName FROM Lead WHERE Id =: leadId];
System.debug('leadList ' + leadList);
if(leadList !=null && !leadList.isEmpty()){
return leadList[0];
}
return leadRec;
}
@AuraEnabled(cacheable=true)
public static String convertLead(Lead leadRec){
System.debug('convert lead');
return 'converted';
}
}