You need to sign in to do that
Don't have an account?
Abilash.S
Trigger to log a call when date changed on Account obj. When date is changed a task(log a call) should create.
Trigger on whenever account is updated the date field is changed then log a call with that date.
I am strucked on
1. How to check date field is changed or not. I need to trigger when existing date changed.
2. Unable to create activity (log a call) on record page. In debug logs getting data to insert. But on record page Call is not logging from apex.
Please help me in code.
// log a call when date field changed in account
public static void logCall(List<Account> newMapps) {
List<Task> tkList = new List<Task>();
Set<Id> regIds = new Set<Id>();
for(Account ac: newMapps){
regIds.add(ac.Id);
}
Map<Id, Account> mapAcc = new Map<Id, Account>([select id, name, support_plan_start_date__c FROM Account WHERE ID IN :regIds]);
system.debug('mapAcc'+mapAcc);
for(Account a : newMapps){
system.debug('77'+a.support_plan_start_date__c);
system.debug('78'+mapAcc.get(a.Id).support_plan_start_date__c);
if(a.support_plan_start_date__c == mapAcc.get(a.Id).support_plan_start_date__c || a.support_plan_start_date__c >mapAcc.get(a.Id).support_plan_start_date__c || a.support_plan_start_date__c <mapAcc.get(a.Id).support_plan_start_date__c){
Task newtask = new Task();
newtask.Description = 'Log a call when datefield changes';
newtask.Priority = 'Normal';
newtask.Status = 'Completed';
newtask.CallDisposition = 'CallBack';
newtask.Subject = 'Call';
newtask.CallType = 'OutBound';
newtask.IsReminderSet = true;
newtask.ReminderDateTime = System.now()+1;
// newtask.WhoId = Trigger.new[0].Id;
tkList.add(newtask);
}
}
system.debug('tkList'+tkList);
try{
if(tkList.size() > 0){
insert tkList;
}
} catch (DmlException e) {
system.debug('Exception caused'+e.getMessage());
}
}
Thanks in advance
I am strucked on
1. How to check date field is changed or not. I need to trigger when existing date changed.
2. Unable to create activity (log a call) on record page. In debug logs getting data to insert. But on record page Call is not logging from apex.
Please help me in code.
// log a call when date field changed in account
public static void logCall(List<Account> newMapps) {
List<Task> tkList = new List<Task>();
Set<Id> regIds = new Set<Id>();
for(Account ac: newMapps){
regIds.add(ac.Id);
}
Map<Id, Account> mapAcc = new Map<Id, Account>([select id, name, support_plan_start_date__c FROM Account WHERE ID IN :regIds]);
system.debug('mapAcc'+mapAcc);
for(Account a : newMapps){
system.debug('77'+a.support_plan_start_date__c);
system.debug('78'+mapAcc.get(a.Id).support_plan_start_date__c);
if(a.support_plan_start_date__c == mapAcc.get(a.Id).support_plan_start_date__c || a.support_plan_start_date__c >mapAcc.get(a.Id).support_plan_start_date__c || a.support_plan_start_date__c <mapAcc.get(a.Id).support_plan_start_date__c){
Task newtask = new Task();
newtask.Description = 'Log a call when datefield changes';
newtask.Priority = 'Normal';
newtask.Status = 'Completed';
newtask.CallDisposition = 'CallBack';
newtask.Subject = 'Call';
newtask.CallType = 'OutBound';
newtask.IsReminderSet = true;
newtask.ReminderDateTime = System.now()+1;
// newtask.WhoId = Trigger.new[0].Id;
tkList.add(newtask);
}
}
system.debug('tkList'+tkList);
try{
if(tkList.size() > 0){
insert tkList;
}
} catch (DmlException e) {
system.debug('Exception caused'+e.getMessage());
}
}
Thanks in advance
The Handler should be as below.
You have to use oldmap and get oldaccount as higlited and then compare with new value
The trigger for the above will be as below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,