+ Start a Discussion
travis.truetttravis.truett 

Add Events to New Opportunity With a Trigger?

I have a triger that is duplicating opportunities when they are set to "Closed Won." When I create those duplicates, There are some events I need to add to them. Is this something I can do in my trigger?
AbdelhakimAbdelhakim
Hi,
You need to create a new trigger "after insert" to create events for duplicated opportunity
You can also use the same trigger and adding new params to it
i.e :
(After update, after insert)


 
Eswar Prasad@Sfdc11Eswar Prasad@Sfdc11
HI travis.truett,

Try this below code you will get idea
public Trigger addopporunityduplicates on Opportunity(after update,after insert)
{
List<id> dup=new List<id>();
   for(Opportunity opp:trigger.old)
   {
    if(opp.status=='closedwon')
    {
     dup.add(opp.id);
     }
    }
}

If you get the answer, please mark it as the correct answer. It will be a help to others who are facing the same problem later.

Regards
Eswar Prasad
travis.truetttravis.truett
My trigger is already duplicating the opportunities just fine. It's adding events to those opportunities once they're created that I'm trying to figure out.
Eswar Prasad@Sfdc11Eswar Prasad@Sfdc11
HI travis.truett ,
Try this below code,if you have duplicate record in those you will finding a status should be closedwon
public Trigger addopporunityduplicates on Opportunity(after update,after insert)
{
List<id> dup=new List<id>();
List<Opportunity> lisopp=[select name,status,phone from Opportunity]
   for(Opportunity opp:lisopp)
   {
    if(opp.status=='closedwon')
    {
     dup.add(opp.id);
     }
    }
}

If you get the answer, please mark it as the correct answer. It will be a help to others who are facing the same problem later.

Regards
Eswar Prasad