How to update current record and related list records by clicking a custom button in Salesforce

How to update current record and related list records by clicking a custom button in Salesforce

Custom Button:




Apex Class:

global class TestCompletionClass{
    webservice static void updateDescription(Id intId){
        Interest__c interest = [SELECT Id, Description__c FROM Interest__c WHERE Id = : intId];
        interest.Description__c = ‘Tested – Ok’;
        update interest;
        
        list<Equipment__c> equipmentList = new list<Equipment__c>();
        equipmentList = [SELECT Id, Description__c FROM Equipment__c WHERE Interest__c = : intId];
        
        if(equipmentList.size() > 0){
            for(Equipment__c eq : equipmentList){
                eq.Description__c = ‘Tested – Ok’;
            }
            update equipmentList;
        }
    }
}



Output:





Leave a Reply