Search In This Blog

2022-11-29

Delete by record id use Schema SObjectType

public without sharing class CustomDeleteCmpController {

    @AuraEnabled(cacheable=true)

    public static String init(Id recordId) {

        // object name

        return recordId.getSobjectType().getDescribe().getLabel();

   }

 

    @AuraEnabled

    public static String doDelete(Id recordId) {

        try {

            String objApiName;

            RecordDelete.deleteLists(new List<SObject>{recordId.getSobjectType().newSObject(recordId)});

            if (String.isNotBlank(recordId)) {

                objApiName = String.valueOf(recordId.getSObjectType());

            }

            return objApiName;

        } catch (Exception ex) {

            throw ex;

        }

    }

}

No comments:

Post a Comment