Im very new to apex or indeed any program language to try not to laugh!
Criteria given to me = if a case is of record type 'travel agent' and the case contact field is populated, update that contacts record custom field 'Luxury_Agent_ID__c' with the Contacts ID.
This is my trigger, no errors are being received but it is not effective. Can anyone advise where I am going wrong, I suspect it is in the latter part of the trigger but I have fiddled about to no avail...
trigger HeroIdfromCase on Case (after insert, after update) {
Set<Id> LuxuryCaseIds = new Set<Id>();
Id recordTypeId = Schema.SObjectType.Case.RecordTypeInfosByName.get('Travel Agent').RecordTypeId;
for (Case c: Trigger.new) {
if( c.RecordTypeId== recordTypeId)
// if case record type is 'Travel Agent'
{
if( c.Contact != null) {
// AND if the case contact field is populated
LuxuryCaseIds.add (c.id);
}
}
List<Contact> ContactsForUpdating = [SELECT Luxury_Agent_ID__c
FROM Contact
WHERE Id IN: LuxuryCaseIds];
for (Contact LX: ContactsForUpdating) {
LX.Luxury_Agent_ID__c = 'LX.Id';
}
update ContactsForUpdating;
}
}