You need to sign in to do that
Don't have an account?
Babar Hussain 13
apex class execution
Hi Everyone,
i was struck on the one condition, my requirement is update the contact status Cancelled when Account status is Cancelled but not update if Account status is "Pending"/"In progress".
I have added my code below , please check let me know how to add that condification or any hints please
public class AccountUpdate { public void getIds() { List<Account> accIds = new List<Account>(); Set<Id> getIds = new Set<Id>(); for(Account a :[select Id, Name from Account]) { getIds.add(a.Id); } System.debug('Print all the Account Ids =>' +getIds); //get the related contacts associated to Account List<Contact> con = [Select Id, Name, AccountId From Contact Where AccountId IN :getIds]; System.debug('Print all related Contacts'+con); List<Contact> getupdateContacts = new List<Contact>(); if(Account.Account_Status__c == 'Cancelled'){ getupdateContacts.add(con); } update getupdateContacts; } } }
Please try the below code and follow the instructions given in the comment.
Please mark it as Best Answer if the above information was helpful.
Thanks.
I am not sure in which context you are planning to execute this method. The code is not optimized. I have simplified and optimized the code.
I hope it will help in the long run.
Regards,
Abdul Aziz Khatri