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
Khushboo Agarwal 4Khushboo Agarwal 4 

test class for

    trigger trgr_UpdateMediaTypeOnOpportunity on Account ( after update) {
        if(UtilityClass.Users_BusinessUnit == ''){
            UtilityClass.Users_BusinessUnit = UtilityClass.getLoggedInUsersBusinessUnit();
        }
        if(UtilityClass.Users_BusinessUnit == 'Display')
        {
            set<ID>acciD = new set<ID>();
            map<Id, String> accValues = new map<ID,String>();
            list<Opportunity> lOpps = new list<Opportunity>();
            List<RecordType> AccRT = [Select id,Name from RecordType where SObjectType='Account'];
            for(Account a: Trigger.new)
            {
                system.debug(a.RecordTypeID);
                if(a.RecordTypeId==AccRT[0].id || a.RecordTypeId==AccRT[1].id)
                accID.add(a.ID); 
            }
            
            if(accID!=null && accID.size()>0)
            {
                for(Account acc : [select Id,Media_Agency_associated__c, RecordType.DeveloperName from Account where id in: accID])
                {
                    if(acc.RecordType.DeveloperName =='Direct')
                        accValues.put(acc.ID,acc.Media_Agency_associated__c);
                    else
                        accValues.put(acc.ID,null);
                }
                system.debug(accValues);
                for(Opportunity opp : [select id, Media_Agency_associated__c,AccountID from Opportunity where AccountID in :accValues.keySet() and (StageName!='Closed Won' OR StageName!='Closed Lost')])
                {
                    system.debug(opp.AccountID);
                    opp.Media_Agency_associated__c = accValues.get(opp.AccountID);
                    lOpps.add(opp);
                }
                
                if(lOpps.size()>0)
                    update lOpps;
            }
        }
        
    }
umesh atryumesh atry
just need to insert account with required filed values and then insert opportunity with specific value
and finally update opportunity value . trigeer will cover automatically.