Не могу удалить запись из lightning:datatable, неособо шарю в js, пожалуйста подскажите кто может срочно
Apex Class
public class ContactsController {
//Get Account Records
@AuraEnabled(cacheable=true)
public static List<Contact> getAccounts (String pageSize, String pageNumber){
List<Contact> contactList = new List<Contact>();
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(Database.getQueryLocator('SELECT Name, Email, Contact_Level__c, Contact_Url__c, Account.Owner.Name, CreatedBy.Name, CreatedDate, Account.Name FROM Contact'));
ssc.setpagesize(Integer.valueOf(pageSize));
ssc.setPageNumber(Integer.valueOf(pageNumber));
contactList = ssc.getRecords();
///////////////////////////////////
List<String> urls = new List<String>();
for (Contact item:contactList){
Id acc = item.AccountId;
Id owner = item.CreatedById;
item.Contact_Url__c = '/lightning/r/Contact/' + Id.valueOf(item.Id) + '/view';
item.Account_Url__c ='/lightning/r/Account/' + Id.valueOf(acc) + '/view';
item.Owner_Url__c ='/lightning/r/Account/' + Id.valueOf(owner) + '/view';
}
return contactList;
}
//Delete Account
@AuraEnabled
public static void deleteContact(Id contact){
Contact delContact = [SELECT Id,Name FROM Contact WHERE Id=:contact];
delete delContact;
}}
handleRowAction: function (component, event, helper) {
var action = event.getParam('action');
switch (action.name) {
case 'edit':
helper.editRecord(component, event);
break;
case 'delete':
helper.deleteRecord(component, event);
break;
case 'view':
helper.viewRecord(component, event);
break;
}
},deleteRecord : function(component, event) {
var row = event.getParam('row');
var action = component.get("c.deleteContact");
console.log(row.Id);
action.setParams({
"contact": row
});
action.setCallback(this, function(response) {
var state = response.getState();
console.log(state);
if (state === "SUCCESS" ) {
var rows = component.get('v.data');
var rowIndex = rows.indexOf(row);
rows.splice(rowIndex, 1);
component.set('v.data', rows);
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "The record has been delete successfully."
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
},var row = event.getParam('row');
var action = component.get("c.deleteContact");
console.log(row.Id);
action.setParams({
"contact": row.Id
});в таком случае, тяжело тебе придется с лайтнингом
должно быть так:
но в реальной ситуации там могут быть и другие причины почему Контакт не хочет удаляться, поэтому раскидывай дебаги в Апекс методе и смотри в Консоль логах дошло ли до выполнения апекс кода и что там происходит