Skip to main content
Hi, I'm using lightning datatable to display available records. I'm using junction object to create a relation between Contact and Custom Object. I was able to get the recordId using the force:hasRecordId, but I'm not able to get the record which is selected in datatable. The requirement is to select multiple records in datatable and add them to parent record's related list, i.e, to the Contact Object related list. When I click on save button, I was successfully inserting a record in junction object but with empty lookup. 

 

I'm sure I'm missing something, Please let me know, below is my Helperfunction that I'm calling from controller.JS

 

insertMailing : function(cmp, event, helper){

 

        var MailingforContact = cmp.get("v.MailingforContact"); 

 

        MailingforContact.Contact__c = cmp.get("v.recordId");

 

        MailingforContact.Available_Mailing__c = cmp.get("v.selectedRow");

 

        

 

        var toastEvent = $A.get('e.force:showToast');

 

        var createAction = cmp.get("c.createMailingRec");

 

        

 

        createAction.setParams({

 

            mailingRec: MailingforContact

 

        });

 

        

 

        createAction.setCallback(this, function(response){

 

           var state = response.getState();

 

            if(state === 'Success'){

 

                var dataMap = response.getReturnValue();

 

                if(dataMap.status == 'Success'){

 

                    toastEvent.setParams({

 

                        'title': 'Success!',

 

                        'type': 'Success',

 

                        'mode': 'dismissable',

 

                        'message': dataMap.message

 

                    });

 

                    toastEvent.fire();

 

                }else if(dataMap.status == 'Error'){

 

                    toastEvent.setParams({

 

                        'title': 'Error',

 

                        'type': 'error',

 

                        'mode': 'dismissable',

 

                        'message': dataMap.message

 

                    });

 

                    toastEvent.fire();

 

                }

 

                    } else {

 

                        alert('Error in getting data');

 

                    }

 

        });

 

            $A.enqueueAction(createAction);

 

        $A.get("e.force:closeQuickAction").fire();

 

    }

 

@ApexController

 

@AuraEnabled

 

    public static Map<String, String> createMailingRec(Mailings__c mailingRec){

 

        Map<String, String> resultMap = new Map<String, String>();

 

        try{

 

            insert mailingRec;

 

            resultMap.put('status', 'Success');

 

            resultMap.put('message', 'Mailing Inserted Successfully');

 

        }

 

        catch (Exception e){

 

            resultMap.put('status', 'Error');

 

            resultMap.put('message', e.getMessage());

 

        }

 

        

 

        return resultMap;

 

    }

 

Anyhelp is appreciated :)
1 件の回答
0/9000