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
hunterhunter 

After Update Trigger error

I'm receiving the error message below from a trigger.  A picklist field in the Sale Object updates with the value "Sold" which, when saved, updates a picklist field in a linked record in the Listing Object with the same value.  At least it did on my previous record.  Now, it does not work.  Does anyone have an idea why this would stop working?

The User ID 005E0000000HkLL belongs to me...the administrator.
The Company ID 00DE0000000HsKC is my company and correct.

Error Message:
Apex script unhandled trigger exception by user/organization: 005E0000000HkLL/00DE0000000HsKC

updateListingStatusfromSale: execution of AfterUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id a070L000013cCjNQAU; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, ERROR:  You can't alter this listing.  Please contact your system administrator.: []

Trigger.updateListingStatusfromSale: line 60, column 1


My Trigger:
trigger updateListingStatusfromSale on Transactions__c (after insert, after update) { Transactions__c[] objects = new Transactions__c[]{}; List<ID> TransIds = New List<ID>(); for(Transactions__c a : Trigger.new) { if(a.Status__c == 'Canceled' ) { TransIds.add(a.Linked_Listing__c); List<Listings__c> TransList = [SELECT id, Listing_Status__c FROM Listings__c WHERE id in :TransIds]; for(integer i = 0 ; i < TransList.size(); i++) { TransList[i].Listing_Status__c = 'Active'; } update TransList; } else if(a.Status__c == 'Contingent -Other' ) { TransIds.add(a.Linked_Listing__c); List<Listings__c> TransList = [SELECT id, Listing_Status__c FROM Listings__c WHERE id in :TransIds]; for(integer i = 0 ; i < TransList.size(); i++) { TransList[i].Listing_Status__c = 'Contingent -Other'; } update TransList; } else if(a.Status__c == 'Contingent -Upon Sale' ) { TransIds.add(a.Linked_Listing__c); List<Listings__c> TransList = [SELECT id, Listing_Status__c FROM Listings__c WHERE id in :TransIds]; for(integer i = 0 ; i < TransList.size(); i++) { TransList[i].Listing_Status__c = 'Contingent -Upon Sale'; } update TransList; } else if(a.Status__c == 'Pending' ) { TransIds.add(a.Linked_Listing__c); List<Listings__c> TransList = [SELECT id, Listing_Status__c FROM Listings__c WHERE id in :TransIds]; for(integer i = 0 ; i < TransList.size(); i++) { TransList[i].Listing_Status__c = 'Pending'; } update TransList; } else if(a.Status__c == 'Sold' ) { TransIds.add(a.Linked_Listing__c); List<Listings__c> TransList = [SELECT id, Listing_Status__c FROM Listings__c WHERE id in :TransIds]; for(integer i = 0 ; i < TransList.size(); i++) { TransList[i].Listing_Status__c = 'Sold'; } update TransList; } } }
Line 60 is "update TransList;"

This used to work on my last launch of the trigger.   Not sure why it doesn't work now.
Shivdeep KumarShivdeep Kumar
Hello,

Please check the custom validation rule on the updated object.  and you can also update your code .
trigger updateListingStatusfromSale on Transactions__c (after insert, after update) { 
	List<ID> TransIds = New List<ID>(); 
	for(Transactions__c a : Trigger.new) {
		if(a.Linked_Listing__c <> null || a.Linked_Listing__c <> ''){
			TransIds.add(a.Linked_Listing__c);
		}
	}

	Map<Id,Listings__c> ListMap = [Select Id, Listing_Status__c from Listings__c where Id IN: TransIds];
	List<Listing__c> listings = New List<Listing__c>();
	For((Transactions__c t : Trigger.New){
		for(Listings__c l : ListMap.Values()){
			if(t.Status__c == 'Canceled' ) {
				Listings__c ls = New Listings__c(Id = l.Id);
				ls.Listing_Status__c = 'Active';
				listings.add(ls);
			}
			if(t.Status__c == 'Contingent -Other' ) {
				Listings__c ls = New Listings__c(Id = l.Id);
				ls.Listing_Status__c = 'Contingent -Other';
				listings.add(ls);
			}
			if(t.Status__c == 'Contingent -Upon Sale' ) {
				Listings__c ls = New Listings__c(Id = l.Id);
				ls.Listing_Status__c = 'Contingent -Upon Sale';
				listings.add(ls);
			}
			if(t.Status__c == 'Pending' ) {
				Listings__c ls = New Listings__c(Id = l.Id);
				ls.Listing_Status__c = 'Pending';
				listings.add(ls);
			}
			if(t.Status__c == 'Sold' ) {
				Listings__c ls = New Listings__c(Id = l.Id);
				ls.Listing_Status__c = 'Sold';
				listings.add(ls);
			}
		}
	}
	if(listings.size() > 0)
		update listings;
}

Please let me know if this help.


Thanks and regards 
Shivdeep