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

Trigger on Equipment Object



I got to write a trigger for the following requirement:


There are 2 custom objects. Service Agreement object and Equipment object.

 Once the equipment has been moved off the service agreement, the ‘Under Contract’ picklist should be defaulted to unchecked and ‘Contract Status’ should changed to ‘Not Under Contract’.




What means "Once the equipment has been moved off the service agreement"? the Equipment has beeen unassigned from Service Agreement?

Where are ‘Contract Status’ and ‘Under Contract’ fields? on Equipment?




Ya once the equipment is un assigned from the service agreement.


Service agreement and Equipment are in a loookup relationship.


Contract Status and Under Contract  are custom fields on the Equipment object.


Ok, try this:


trigger UnAssignServiceAgreement on Equipment__c (before insert, before update) {
	for (Equipment__c equipment : {
		if (equipment.ServiceAgreement__c == null) {
			equipment.Under_Contract__c = 'unchecked';
			equipment.Contract_Status__c = 'Not Under Contract';



But probably is better do it on a workflow.


I got the following error:


Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UnAssignServiceAgreement caused an unexpected exception, contact your administrator: UnAssignServiceAgreement: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.UnAssignServiceAgreement: line 4, column 1
Can u explain the workflow process>?