You need to sign in to do that
Don't have an account?
Monet Zamaripa 3
Hi! I was able to create my first Event trigger to update an opportunity field but am having problems creating a test class. Any assistance is appreciated!
trigger updateOpportunty on Event (after update) {
List<Id> OpportuntyIds=new List<Id>();
List<Opportunity> OpportunitysToUpdate =new List<Opportunity>();
for(Event e:trigger.new){
if(String.valueOf(e.whatId).startsWith('006') == TRUE)
if((e.subject).contains('First Meeting'))
{//check if the task is associated with a Opportunty
OpportuntyIds.add(e.whatId);
}
}
Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([SELECT Id,Meeting_Initially_Scheduled_Date__c FROM Opportunity WHERE Id IN :OpportuntyIds]);
For (Event e:trigger.new){
Opportunity opp = OpportunityMap.get(e.whatId);
opp.Meeting_Initially_Scheduled_Date__c = e.Initially_Scheduled__c;
OpportunitysToUpdate.add(opp);
}
try{
update OpportunitysToUpdate;
}catch(DMLException e){
system.debug('Opportunitys were not all properly updated. Error: '+e);
}
}
List<Id> OpportuntyIds=new List<Id>();
List<Opportunity> OpportunitysToUpdate =new List<Opportunity>();
for(Event e:trigger.new){
if(String.valueOf(e.whatId).startsWith('006') == TRUE)
if((e.subject).contains('First Meeting'))
{//check if the task is associated with a Opportunty
OpportuntyIds.add(e.whatId);
}
}
Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([SELECT Id,Meeting_Initially_Scheduled_Date__c FROM Opportunity WHERE Id IN :OpportuntyIds]);
For (Event e:trigger.new){
Opportunity opp = OpportunityMap.get(e.whatId);
opp.Meeting_Initially_Scheduled_Date__c = e.Initially_Scheduled__c;
OpportunitysToUpdate.add(opp);
}
try{
update OpportunitysToUpdate;
}catch(DMLException e){
system.debug('Opportunitys were not all properly updated. Error: '+e);
}
}
Actually in my code I creted those filed as Text. Changed now.Try the below code .Please mark this as solved if this solves your problem.Thanks.
All Answers
Try something like this .
Actually in my code I creted those filed as Text. Changed now.Try the below code .Please mark this as solved if this solves your problem.Thanks.