• MeghanNYC
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I'm a newbie, so please be patient!

 

I wrote the following trigger to create a contract when an opportunity closes (not exactly the best use of the contract process, but that's another story)

 

The trigger is supposed to create a contract and tie the contract to the opportunity.  Works perfectly - except it creates 2 contracts.

 

Any ideas on how I can enforce a 1:1 between opportunities and contracts?

 

Any help is most appreciated!!

 

 

trigger UpdOpportunityOnStageChange on Opportunity (after update) {

List<Contract> contracts = new List<Contract>();

for (Opportunity a: Trigger.New) {

if (a.StageName == 'Contract Signed') {

contracts.add(new Contract(

CustomerSignedTitle = a.Type,

ContractTerm = 12,

Status = 'Draft',

Opportunity__c = a.Id,

AccountId = a.AccountId,

StartDate = System.today()));

}

}

insert contracts;

}