1

Im a newbie please bear with me. Im making a trigger that should be activated with 2 objects, After update in Opportunity and After update in Contracts. The requirement is that Contracts will only be activated once the opportunity stage is Closed Won. And an error will be displayed if I try to activate the contract not having Closed won stage.

trigger ActivateContract on Opportunity (after update) {
List <Contract> cont_List = new List <Contract>();
Set <ID> oppId = new Set <ID>();
for (Opportunity oppo : Trigger.new){
    if( oppo.StageName != 'Closed Won'){
    oppId.add(oppo.ContractId);
    }
     cont_List = [Select Id, Active__c FROM Contract WHERE AccountID IN : oppId];     
    for(Contract cont : cont_List){
        cont.Active__c = false;
        update cont;
    }

}
}
  • There is no connection between Contracts and opportunity status in validation rule. – sfdclearner Oct 6 '15 at 2:32
0

You are right there is not a relationship between opportunity and Contract, but then if there are multiple opportunities and some are lost and some are won, then how do you know which opportunity to look at. Maybe you can add an Opportunity lookup then you could use the validation rule.

Otherwise, do a rollup summary on account counting the number of Opportunities not in closed won. Then pull that into the contract, then do validation rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.