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
GRStevenBrookesGRStevenBrookes 

Guidance with simple trigger

Hi all,

 

Hope you are all well!

 

Correct me if am wrong, this should be quite simple but cant seem to get my head around it!!

 

2 Objects concerned are Service_Implementation__c and the Standard 'Task' object.

 

What I would like is for when a user creates a task where (Task) RecordType=01220000000JPYY that the 'Description' field on the Task is copied to a field on the 'related to' (which will always be of type 'Service_Implementation__c') called Last_Implementation_Note__c

 

Thats it!

 

Any help appreciated.

 

Steve

 

Taiki YoshikawaTaiki Yoshikawa

Hi,

 

hope this is thing you are looking for.

 

trigger TaskTrigger on Task (after insert) {
	
	Set<Id> taskIds = new Set<Id>();
	Map<Id, Task> taskMap = new Map<Id, Task>();
	
	RecordType r = [select Id from RecordType where SobjectType = 'Task' and DeveloperName = 'SampleName'];
	
	for (Task t : Trigger.new) {
		if (t.RecordTypeId == r.Id) {
			taskIds.add(t.WhatId);
			taskMap.put(t.WhatId, t);
		}
	}
	
	List<Service_Implementation__c> services =
	[
		select
			Id
			,Last_Implementation_Note__c
		from
			Service_Implementation__c
		where
			Id IN: taskIds
	];
	
	for (Service_Implementation__c s : services) {
		s.Last_Implementation_Note__c = taskMap.get(s.Id).Description;
	}
	
	update services;

}