You need to sign in to do that
Don't have an account?
Urvik
Apex Controller Help
Could someone please help why the following code is not working??
________
public class THUpdateLRO extends AbcTriggerHandler {
private void updateLRO(List<License_Registration__c> newLROs) {
Set<id> AccIds = new Set<id>();
for (License_Registration__c c : newLROs){
AccIds.add(c.Current_Application__c);
}
Map<id, Application__c> AccIDmap = new Map<id, Application__c>([Select Id, Application_Outcome__c from Application__c
Where Id in :AccIds]);
for (License_Registration__c LicReg : newLROs){
if(LicReg.Current_Application__c != null && LicReg.Current_Application__r.Application_Status__c == 'Withdrawn'){
LicReg.Status__c = AccIDmap.get(LicReg.Current_Application__c).Application_Outcome__c;
}
}
}
public override void OnBeforeInsert(SObject[] newObjects){
updateLRO((List<License_Registration__c>)newObjects);
}
public override void OnBeforeUpdate(SObject[] newObjects,
Map<Id,SObject> newObjectMap,
SObject[] oldObjects,
Map<Id,SObject> oldObjectMap){
updateLRO((List<License_Registration__c>)newObjects);
}
}
________
public class THUpdateLRO extends AbcTriggerHandler {
private void updateLRO(List<License_Registration__c> newLROs) {
Set<id> AccIds = new Set<id>();
for (License_Registration__c c : newLROs){
AccIds.add(c.Current_Application__c);
}
Map<id, Application__c> AccIDmap = new Map<id, Application__c>([Select Id, Application_Outcome__c from Application__c
Where Id in :AccIds]);
for (License_Registration__c LicReg : newLROs){
if(LicReg.Current_Application__c != null && LicReg.Current_Application__r.Application_Status__c == 'Withdrawn'){
LicReg.Status__c = AccIDmap.get(LicReg.Current_Application__c).Application_Outcome__c;
}
}
}
public override void OnBeforeInsert(SObject[] newObjects){
updateLRO((List<License_Registration__c>)newObjects);
}
public override void OnBeforeUpdate(SObject[] newObjects,
Map<Id,SObject> newObjectMap,
SObject[] oldObjects,
Map<Id,SObject> oldObjectMap){
updateLRO((List<License_Registration__c>)newObjects);
}
}
LicReg.Current_Application__r.Application_Status__c
When a trigger fires I believe it only gives you access to the objects direct fields. Since you are already building a map and grabbing those objects try something like this.
for (License_Registration__c LicReg : newLROs){
Application__c application = AccIDmap.get(LicReg.Current_Application__c);
if(application != null && application.Application_Status__c == 'Withdrawn'){
LicReg.Status__c = application.Application_Outcome__c;
}
}
Don't forget to add that field to your query on the application__c object.
Map<id, Application__c> AccIDmap = new Map<id, Application__c>([Select Id, Application_Outcome__c,Application_Status__c from Application__c
Where Id in :AccIds]);