You need to sign in to do that
Don't have an account?
Keri-An Richards 9
Update Lines from Contract Activaton
Hi all,
Hoping I can beg some help again with another trigger. I need to update a list of custom objects (Contract Lines) when a contract is activated.
Appreciate any help I can get.
Keri-An
Hoping I can beg some help again with another trigger. I need to update a list of custom objects (Contract Lines) when a contract is activated.
Appreciate any help I can get.
Keri-An
Hi Kerl-An,
Assuming your contract lines have a lookup on ContractNumber field of Contract object, I have written the following piece of code, which is working fine.
You may need to customize a bit to suit your other requirements. However, the basic requirement that you have mentioned in the post can be fulfilled with the following piece of code. CheckRecurisveTrigger class needs to be created to avoid recursive trigger.
Trigger:
trigger updateContractLine on Contract(after insert, after update) {
if(CheckRecursiveTrigger.runOnce())
{
for (Contract con: Trigger.new)
{
Contract k = [select Id, ContractNumber,status from Contract where Id IN : trigger.new];
String contnumber=k.ContractNumber ;
List<Contract_Line__c> clc = [Select Id, Contract_Line_Status__c from Contract_Line__c where
Contract__r.ContractNumber = :contnumber];
if (k.status == 'Activated')
{
for (Contract_Line__c c: clc)
{
c.Contract_line_status__c = 'Active';
}
update clc;
}
}
}
}
CheckRecursiveTrigger Class:
public class CheckRecursiveTrigger {
private static boolean run = true;
public static boolean runOnce(){
if (run)
{
run=false;
return true;
}
else
{
return false;
}
}
}
If this suits your requirements, please do not forget to mark as the solution :).
All Answers
If I understood it correctly, if Status field of Contract is changed to 'Activated', you need to update a list custom objects. In this case, the custome object name is Contract Lines.
So, what would like to update on this custom object. You want to update a field?
Please let me know, to give you a right reply
I thought i might not have been clear enough.
I need a trigger so that when the Activate button is clicked (std Salesforce button) on a Contract (thereby updating it's status to Activated), I need to update the status on the Contract Lines custom object.
Status on Contracts is Draft, Activated and Expired
Status on Contract Lines is Pending, Active and Inactive
There can be many Contract Lines on a Contract (similar set up to Opportunity and Opportunity Line Items)
Is that enough information?
Hi Kerl-An,
Assuming your contract lines have a lookup on ContractNumber field of Contract object, I have written the following piece of code, which is working fine.
You may need to customize a bit to suit your other requirements. However, the basic requirement that you have mentioned in the post can be fulfilled with the following piece of code. CheckRecurisveTrigger class needs to be created to avoid recursive trigger.
Trigger:
trigger updateContractLine on Contract(after insert, after update) {
if(CheckRecursiveTrigger.runOnce())
{
for (Contract con: Trigger.new)
{
Contract k = [select Id, ContractNumber,status from Contract where Id IN : trigger.new];
String contnumber=k.ContractNumber ;
List<Contract_Line__c> clc = [Select Id, Contract_Line_Status__c from Contract_Line__c where
Contract__r.ContractNumber = :contnumber];
if (k.status == 'Activated')
{
for (Contract_Line__c c: clc)
{
c.Contract_line_status__c = 'Active';
}
update clc;
}
}
}
}
CheckRecursiveTrigger Class:
public class CheckRecursiveTrigger {
private static boolean run = true;
public static boolean runOnce(){
if (run)
{
run=false;
return true;
}
else
{
return false;
}
}
}
If this suits your requirements, please do not forget to mark as the solution :).
How can I change this to update the contract lines once the Contract is Expired?
I have a workflow that has a time based field update that amends the Contract status to Expired on the day it finishes. I also need to mark the contract lines as Inactive when that happens.
Thanks