+1 vote
by (163k points)

I'* creating a custom lead conversion page, I'* 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 }){
            this.varLeadRecord = data;
            console.log('this.varLeadRecord please');
        }else if(error){

        console.log('convert button is clicked'); //this is OK
        console.log(this.varLeadRecord); //
        convertLead({leadRec: '$this.varLeadRecord'})
        .then(result => {
        .catch(error => {
            this.error = error;

Here is my APEX controller

public class apexController{
    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;       
    public static String convertLead(Lead leadRec){
        System.debug('convert lead');
        return 'converted';

1 Answer

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.