You need to sign in to do that
Don't have an account?
dcgb2332
Need test class for trigger on Opportunity Owner
Here is my code, if someone could please help me with a test class, I would greatly appreciate it!
`trigger setOpportunityOwner on Task (before insert, before update) {
Set<Id> oppIds = new Set<Id>();
for ( Task newTask : Trigger.new ) {
if ( newTask.WhatId != null && String.valueOf( newTask.WhatId ).startsWith( '006' ) ) {
oppIds.add( newTask.WhatId );
}
}
Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([Select Owner.Name FROM Opportunity WHERE Id IN :oppIds]);
for(Task newTask: Trigger.new) {
if ( oppMap.containsKey( newTask.WhatId ) ) {
newTask.Opp_Owner__c = oppMap.get( newTask.WhatId ).Owner.Name;
}
}
}`
`trigger setOpportunityOwner on Task (before insert, before update) {
Set<Id> oppIds = new Set<Id>();
for ( Task newTask : Trigger.new ) {
if ( newTask.WhatId != null && String.valueOf( newTask.WhatId ).startsWith( '006' ) ) {
oppIds.add( newTask.WhatId );
}
}
Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([Select Owner.Name FROM Opportunity WHERE Id IN :oppIds]);
for(Task newTask: Trigger.new) {
if ( oppMap.containsKey( newTask.WhatId ) ) {
newTask.Opp_Owner__c = oppMap.get( newTask.WhatId ).Owner.Name;
}
}
}`
Trigger Test Class - This test class has 100% code coverage.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
All Answers
Trigger Test Class - This test class has 100% code coverage.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Make sure you have selected Run Specified Tests during deployment.
Run Specified Tests: Only specified test classes will run with this option. You to provide specified tests in comma-separated list.