This would be an ‘after update’ trigger on the Account object. The trigger checks if the status has changed to ‘Inactive’ and then updates the status of all related Opportunities to ‘Closed Lost’.
trigger CloseRelatedOpportunities on Account (after update) {
List<Opportunity> oppsToUpdate = new List<Opportunity>();
for(Account acc : Trigger.new){
if(acc.Status__c == ‘Inactive’ && (Trigger.oldMap.get(acc.Id).Status__c != ‘Inactive’)){
oppsToUpdate.addAll([SELECT Id FROM Opportunity WHERE AccountId = :acc.Id AND StageName != ‘Closed Lost’]);
}
}
for(Opportunity opp : oppsToUpdate){
opp.StageName = ‘Closed Lost’;
}
if(!oppsToUpdate.isEmpty()){
update oppsToUpdate;
}
}