Created
September 2, 2014 16:48
-
-
Save joshbirk/1158f15bff7a8f974400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NewProj2 isn't a meaningful Apex name. NewProjectTrigger? | |
trigger NewProj2 on Opportunity (before update) { | |
for (Opportunity o : Trigger.new) | |
{ | |
if(o.StageName == 'Closed Won') | |
{ | |
try | |
{ | |
SFL5_Projects__c[] proj = [Select Name From SFL5_Projects__c | |
WHERE Opportunity__c = :o.Id]; | |
Integer i = 0; | |
for(SFL5_Projects__c p1:proj) | |
{ | |
i++; | |
} | |
if(i == 0) //instead of all of this, you could just do proj[0] | |
//but why only operate on this one? Why not all the projects? | |
{ | |
SFL5_Projects__c p2 = new SFL5_Projects__c(Client__c = o.AccountId, Opportunity__c = o.Id, Name = o.Name); | |
Insert p2; | |
} | |
} | |
catch(Exception e){} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment