I am trying to populate the Task with related data even before creating a task. For example in this Task creation, I have RelatedTo(Loan) autofilled, similarly I want LoanNumber and ClientName to be auto filled which are fields from Loan object.
I have created a Trigger but that is working only after creating a Task but not before,
trigger updateLoan_Task on Task (before insert, before update) {
Set<Id> LoanIDs = new Set<Id>();
for (Task t : Trigger.new) {
if (t.WhatId != null && String.valueOf(t.WhatId).startsWith('a0Q')) {
LoanIDs.add(t.WhatId);
}
}
Map<Id, Loan_New__c> loan = new Map<Id, Loan_New__c>([Select Id, LoanNumber__c, Client_Name__c from Loan_New__c where Id in :LoanIDs]);
for (Task t : Trigger.new) {
if (t.WhatId != null && String.valueOf(t.WhatId).startsWith('a0Q')) {
Loan_New__c l = loan.get(t.WhatId);
t.test_loanNumber__c = l.LoanNumber__c;
t.Client_name__c = l.Client_Name__c;
}
}
}
Is there any way I can populate this info before creating a task, I checked this from the other Post but my scenario is different. Any suggestions?
Thanks.
WhatId
more programatically i.e.t.WhatId.getSObjectType() == My_Object__c.sObjectType
.