You need to sign in to do that
Don't have an account?
Khushboo 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;
}
}
}
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;
}
}
}
and finally update opportunity value . trigeer will cover automatically.