Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * @see https://success.salesforce.com/answers?id=90630000000hdCVAAY
- */
- trigger LaatsteCallMobileMiles on Task (after insert) {
- // Retrieve the email addresses of CreatedBy users for tasks currently
- // being processed by the trigger
- List<Task> newTasks = [
- SELECT Id, WhatId, Subject, CreatedDate, CreatedBy.Email
- FROM Task
- WHERE Id IN :Trigger.new
- ];
- // Initialize a map of accounts to update, based on the Related To
- // (WhatId) field on the task. The map will be keyed on the Account ID,
- // to make sure the same account is not included twice in a single DML
- // operation.
- Map<Id, Account> affectedAccountsById = new Map<Id, Account>();
- // Go through the new tasks and check to see whether the account shoudl
- // be updated, based on the email address and subject criteria
- for (Task eachTask : newTasks) {
- if (eachTask.WhatId != null) {
- if (eachTask.CreatedBy.Email.contains('@mobilemiles.nl')
- && eachTask.Subject.contains('Made call to')) {
- // Construct the Account record to update
- Account affectedAccount = new Account(
- Id = eachTask.WhatId,
- Laatste_activiteit_Mobile_Miles__c = eachTask.CreatedDate);
- // Put the affected account in the map
- affectedAccountsById.put(affectedAccount.Id, affectedAccount);
- }
- } // if (eachTask.WhatId != null)
- } // for each Task in newTasks
- // Update any affected accounts
- if (!affectedAccountsById.isEmpty())
- update affectedAccountsById.values();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement