function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
WikWik 

Error in the Trigger

Hi,

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.

I have written a piece of trigger. Is there any failure or Governer Limits of Apex will it serve my 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;

PrathyushaPrathyusha
Your code looks good, you should be good to go.
WikWik

This code is not performing the desired action. Actually it's doing nothing.