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

Check related object records on Opportunity on Opportunity Stage changed.

I have one custom object margin_calculator_... and this object have lookup of Opportunity.when we update Opportunity at a particular stage here [ stagename-'Margin cal...' () ]in this stage if there is at least one record in my custom object margin_calculator_... it should allow to update oppty at this stage or if there is no custom object records for that oppty it should not allow to update oppty at that stage.
i tried too much but not able to do in both code is working 
but something is missing please help me out.
Thanks in advance.
your help will be appericiated.
my code is as follows-
trigger OpportunityTrigger on Opportunity (before update) {
    List<Margin_Calculator_Version__c> marginLst =new List<Margin_Calculator_Version__c>();    
    marginLst = [SELECT Id, Name, Opportunity__r.Id FROM Margin_Calculator_Version__c WHERE Opportunity__r.Id IN]; 
            for(Margin_Calculator_Version__c marginversion:marginLst){
                Set<Id> oppId = new Set<Id>();
                if((oppId.Contains(opp.Id)) && (opp.StageName=='Margin Calculation'))
                    update opp;
                    opp.addError('Please create one record in margin version');

ooheman dasooheman das