function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Frank CarterFrank Carter 

Lightning - list button to delete records

Hello,
I created an object, Billing Detail, for invoices. It's related on opportunity. Every Opportunity won must have one or more billing details. An object  Billing detail can be of type PPU(pay for use), UNA TANTUM and FEE(canon). We have several button on related list billing detail on opportunity. "New" to create with a trigger multiple object billing details on that opportunity. Example if we have an annual contract with monthly invoice we can create with one click 12 billing details. The javascript buttons That I want on lightning are: Delete PPu, Delete UNA TANTUM , DElete FEE. THese buttons make a query to delete  a type of billing details example If i click "Delete FEE" the button deletes only the billing detail of type FEE except for the FEe in status BILLED. I need this button with this function on lightning. I tried creating a vf page with inside the javascript code but is not working. I want to know waht is the correct approach to have the same button on related list on Lightning?
 
Frank CarterFrank Carter
I created a Lightning component:
<aura:component controller="LcDeleteFeeController" implements="force:lightningQuickAction" access="global" >

<aura:attribute name="opp" type="Opportunity"/>

<lightning:button aura:id="deleteDataButton"
                     label="Delete FEE"
                     class="slds-button slds-button__icon--left slds-button--destructive"
                     onclick="{!v.deleteData}" 
                     iconName="utility:delete"
              />

</aura:component>

controller:
({

    deleteData: function(component, event, helper){
        var action = component.get("c.deleteData");
         action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
                 toastEvent.setParams({
                "title": "Delete!",
                "message": "Data were succesfully deleted.",
                "type": "other",
                "key":"delete"
            });
                toastEvent.fire();
        }
    });
         $A.enqueueAction(action);
    },
})

apex class:
public with sharing class LcDeleteFeeController {

@AuraEnabled
    public static void deleteData() {
        try {
            List<Billing_Detail__c> canc = [Select Id From Billing_Detail__c Where Billing_Detail__c=: Opportunity.Id AND Billing_Status__c!='Billed' AND Billing_Type__c ='FEE'];
           if(Schema.sObjectType.Billing_Detail__c.isDeletable())
            delete canc;
        } catch (Exception e) {
            throw new AuraHandledException('Unable to delete auth: ' + e.getMessage());
        }
    }

}

I have this error when I try to save apex class
Invalid bind expression type of Schema.SObjectField for column of type Id

Can someone help me?

thanks,
Frank​​​