You need to sign in to do that
Don't have an account?
Wik
Trigger On Service Agreement Object
Hi,
Need to write a trigger on the following requirement:
When the ‘Active’ status on the attached Service Agreement object goes to ‘Inactive’, the associated Equipment Object's field is marked on the ‘Contract Status’ field with ‘Under Expired Contract’.
The service agreement object is in lookup relationship with the equipment object.
Hi,
Oh yes, I think you'll only need that to be after Update.
The reason I added this line: if(serv.Status__c == 'Inactive' && ( trigger.isInsert || serv.Status__c != trigger.oldMap.get(serv.id).Status__c)) is because I kept trigger on isInsert, but after update should get you what you need.
And yes, the code that you wrote just now should serve the purpose.
All Answers
Hi,
Here is the sample trigger that you can start off with...Change the API names of obects and fields that I'm using
Hi,
I think this would be a after update trigger.
May you explain the following code:
if(serv.Status__c == 'Inactive' && ( trigger.isInsert || serv.Status__c != trigger.oldMap.get(serv.id).Status__c))
equipmentIds.add(serv.Equipments__c);
Hi,
Will the following serve the purpose
trigger serviceAgreementInactive on Service_Agreement__c(after update){
Map<ID, Service_Agreement__c > oldMap = new Map<ID,Service_Agreement__c >(Trigger.old);
List<Id> equipmentIds = new List<Id>();
for(Service_Agreement__c serv : trigger.new){
if(serv.status__c == 'Inactive' && oldMap.get(serv.Id).status__c !='Inactive')
equipmentIds.add(serv.Id);
}
List<Equipment__c> equipmentsToMakeExpire = [Select id, Contract_Status__c from Equipment__c where id IN :equipmentIds];
for(Equipment__c e : equipmentsToMakeExpire)
e.Contract_Status__c = 'Under Expired Contract';
if(!equipmentsToMakeExpire.isEmpty()) update equipmentsToMakeExpire;
}
Hi,
Oh yes, I think you'll only need that to be after Update.
The reason I added this line: if(serv.Status__c == 'Inactive' && ( trigger.isInsert || serv.Status__c != trigger.oldMap.get(serv.id).Status__c)) is because I kept trigger on isInsert, but after update should get you what you need.
And yes, the code that you wrote just now should serve the purpose.
Thanx a lot.
Hey it's actually not performing the desired action.
It's actually doing nothing.