+ Start a Discussion

Trigger causing Contract Dupes

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;






Do you have any further triggers running for opportunity or contracts? In addition, when is the Opportunity Stage changed, because, every time the opportunity is modified with the 'Contract Signed' stage you'll create a new Contract

Kiran  KurellaKiran Kurella

Insert the Contract only if the old Opportunity StageName is not Contract Signed.



if ((:Trigger.oldMap.get(a.Id).StageName != 'Contract Signed') && (a.StageName == 'Contract Signed')) {