You need to sign in to do that
Don't have an account?
Ken sfdc1
· "Active Persistence Status" picklist from case -- adherence record type update on Account record
· 1. On Drug - Will Re-Order
· 2. On Drug - Unlikely to Re-Order
· 3. Not on Drug - Unlikely to Re-Start
Trigger CaseAfterInsertUpdate on Case (after insert, after update) {
Set<String> caseIds = new Set<String>();
for (Case c : Trigger.new)
{
if(Trigger.isInsert)
{
caseIds.add(c.Id);
}
else
{
Case oldCase = Trigger.oldMap.get(c.Id);
if(oldCase.Nutrition_Consult_Dietitian__c != c.Nutrition_Consult_Dietitian__c)
{
caseIds.add(c.Id);
}
}
}
RecordType rt = [select Id from RecordType where Name = 'Nutrition Consult' and sObjectType = 'Case'];
Map<String, String> AccountMap = new Map<String, String>();
for(Case c : [select Nutrition_Consult_Dietitian__c, AccountId from Case where Id in :caseIds and (Type = 'Initial' or Type = 'Follow Up') and RecordTypeId = :rt.Id])
{
AccountMap.put(c.AccountId, c.Nutrition_Consult_Dietitian__c);
}
List<Account> accounts = new List<Account>();
for(Account acc : [select Id, RD_Consult__c from Account where Id in :AccountMap.keySet()])
{
acc.RD_Consult__c = AccountMap.get(acc.Id);
accounts.add(acc);
}
try {
update accounts;
} catch (Exception ex) {
System.debug('Could not update Last Survey Sent field on Account with cause: ' + ex.getCause());
}
}
Add the logic to this trigger pls
Add logic to existing trigger case to account field update
· "Active Persistence Status" picklist from case -- adherence record type update on Account record
· 1. On Drug - Will Re-Order
· 2. On Drug - Unlikely to Re-Order
· 3. Not on Drug - Unlikely to Re-Start
Trigger CaseAfterInsertUpdate on Case (after insert, after update) {
Set<String> caseIds = new Set<String>();
for (Case c : Trigger.new)
{
if(Trigger.isInsert)
{
caseIds.add(c.Id);
}
else
{
Case oldCase = Trigger.oldMap.get(c.Id);
if(oldCase.Nutrition_Consult_Dietitian__c != c.Nutrition_Consult_Dietitian__c)
{
caseIds.add(c.Id);
}
}
}
RecordType rt = [select Id from RecordType where Name = 'Nutrition Consult' and sObjectType = 'Case'];
Map<String, String> AccountMap = new Map<String, String>();
for(Case c : [select Nutrition_Consult_Dietitian__c, AccountId from Case where Id in :caseIds and (Type = 'Initial' or Type = 'Follow Up') and RecordTypeId = :rt.Id])
{
AccountMap.put(c.AccountId, c.Nutrition_Consult_Dietitian__c);
}
List<Account> accounts = new List<Account>();
for(Account acc : [select Id, RD_Consult__c from Account where Id in :AccountMap.keySet()])
{
acc.RD_Consult__c = AccountMap.get(acc.Id);
accounts.add(acc);
}
try {
update accounts;
} catch (Exception ex) {
System.debug('Could not update Last Survey Sent field on Account with cause: ' + ex.getCause());
}
}
Add the logic to this trigger pls
Try with below code it wil work for sure !
Let me know if it helps !!!
Thanks
Manoj
All Answers
· 1. On Drug - Will Re-Order
· 2. On Drug - Unlikely to Re-Order
· 3. Not on Drug - Unlikely to Re-Start
List<Account> accList = new List<Account>();
for (Case c : Trigger.new) {
Account acc = new Account(
Id = c.Account.Id,
Active_Persistence_Status__c = c.Active_Persistence_Status__c
);
accList.add(acc);
}
try {
update accList;
} catch (Exception ex) {
System.debug('Could not update Last Survey Sent field on Account with cause: ' + ex.getCause());
}
}
My trigger is not working can anyone verify according to it.
Try with below code it wil work for sure !
Let me know if it helps !!!
Thanks
Manoj