trigger OpportunityTracking on Opportunity (after update) {
for (Opportunity opp : Trigger.new) {
if (opp.StageName == 'Closed Won' &&
Trigger.oldMap.get(opp.Id).StageName != 'Closed Won') {
Performance_Tracker__c tracker = new Performance_Tracker__c(
Sales_Rep__c = opp.OwnerId,
Opportunity_Amount__c = opp.Amount,
Close_Date__c = opp.CloseDate
);
insert tracker;
}
}
}
dHJpZ2dlciBPcHBvcnR1bml0eVRyYWNraW5nIG9uIE9wcG9ydHVuaXR5IChhZnRlciB1cGRhdGUpIHsKICAgIGZvciAoT3Bwb3J0dW5pdHkgb3BwIDogVHJpZ2dlci5uZXcpIHsKICAgICAgICBpZiAob3BwLlN0YWdlTmFtZSA9PSAnQ2xvc2VkIFdvbicgJiYgCiAgICAgICAgICAgIFRyaWdnZXIub2xkTWFwLmdldChvcHAuSWQpLlN0YWdlTmFtZSAhPSAnQ2xvc2VkIFdvbicpIHsKICAgICAgICAgICAgUGVyZm9ybWFuY2VfVHJhY2tlcl9fYyB0cmFja2VyID0gbmV3IFBlcmZvcm1hbmNlX1RyYWNrZXJfX2MoCiAgICAgICAgICAgICAgICBTYWxlc19SZXBfX2MgPSBvcHAuT3duZXJJZCwKICAgICAgICAgICAgICAgIE9wcG9ydHVuaXR5X0Ftb3VudF9fYyA9IG9wcC5BbW91bnQsCiAgICAgICAgICAgICAgICBDbG9zZV9EYXRlX19jID0gb3BwLkNsb3NlRGF0ZQogICAgICAgICAgICApOwogICAgICAgICAgICBpbnNlcnQgdHJhY2tlcjsKICAgICAgICB9CiAgICB9Cn0K