You need to sign in to do that
Don't have an account?
Apurva Dutta 8
Need Help with Before Update Trigger
Hi,
I have two Objects Case and Case_Action__c. Whenever a case's Contract status is changed to Rejected, it should create a record in Case Action Object. Now, if the Case Action status is changed to "Resubmitted", the case's contract status should also be updated to "Resubmitted" and in a Date time field the Date/Time should get capture. Now, if Case's Contract statsu is again changed to "Rejected", it should again create a Case Action record. Now, if 2nd Case action status record is updated to "Resubmitted", it should update the case's contract status field to "Resubmitted" , but the date/time should be capture in the second date/time field.
I have come up with below trigger, which populates the 1st date/time field but not the second one. Could anybody please tell me what i am doing wrong here?
trigger updateCaseOwner on Case_Action__c (before update)
{
Map<Id,Case_Action__c> casActonMap = new Map<Id,Case_Action__c>();
casActonMap = Trigger.OldMap;
Set<Id> casID = new Set<Id>();
Integer Count =0;
List<Case> casLst = new List<Case>();
for(Case_Action__c casActon : trigger.new)
{
casID.add(casActon.Case__c);
}
List<Case> casObjLst = [Select Id,Contract_Status__c,Sales_Resubmit_Comments__c,Sales_Resubmission_Date__c,X2nd_Sales_Resubmission_Date__c from Case where Id in : casID];
for(Case_Action__c casActonObj : Trigger.new)
{
Case_Action__c casActnOld = new Case_Action__c();
casActnOld = casActonMap.get(casActonObj.Id);
if(casActonObj.Status__c == 'Resubmitted' && casActnOld.Status__c != 'Resubmitted')
{
for(case cas :casObjLst)
{
//Count = 0;
system.debug('cas.Sales_Resubmission_Date__c----'+cas.Sales_Resubmission_Date__c);
system.debug('cas.X2nd_Sales_Resubmission_Date__c------'+cas.X2nd_Sales_Resubmission_Date__c);
system.debug('Count----'+Count);
if(Count == 0 && cas.Sales_Resubmission_Date__c == null)
{
System.debug('Checking if entering into the loop-------');
cas.Contract_Status__c = 'Resubmitted';
cas.Sales_Resubmit_Comments__c = casActonObj.Resubmit_Comments__c;
cas.Sales_Resubmission_Date__c = System.now();
Count++;
system.debug('Count--1--'+Count);
casLst.add(cas);
}
else if( count == 1 && cas.Sales_Resubmission_Date__c != null)
{
system.debug('Count--2--'+Count);
System.debug('Checking else entering into the loop----1---');
cas.Contract_Status__c = 'Resubmitted';
cas.Sales_Resubmit_Comments__c = casActonObj.Resubmit_Comments__c;
cas.X2nd_Sales_Resubmission_Date__c = System.now();
casLst.add(cas);
}
Count++;
}
}
}
system.debug('Count--3--'+Count);
//Count++;
system.debug('Count--4--'+Count);
system.debug('casLst------'+casLst);
update casLst;
}
Thank You.
I have two Objects Case and Case_Action__c. Whenever a case's Contract status is changed to Rejected, it should create a record in Case Action Object. Now, if the Case Action status is changed to "Resubmitted", the case's contract status should also be updated to "Resubmitted" and in a Date time field the Date/Time should get capture. Now, if Case's Contract statsu is again changed to "Rejected", it should again create a Case Action record. Now, if 2nd Case action status record is updated to "Resubmitted", it should update the case's contract status field to "Resubmitted" , but the date/time should be capture in the second date/time field.
I have come up with below trigger, which populates the 1st date/time field but not the second one. Could anybody please tell me what i am doing wrong here?
trigger updateCaseOwner on Case_Action__c (before update)
{
Map<Id,Case_Action__c> casActonMap = new Map<Id,Case_Action__c>();
casActonMap = Trigger.OldMap;
Set<Id> casID = new Set<Id>();
Integer Count =0;
List<Case> casLst = new List<Case>();
for(Case_Action__c casActon : trigger.new)
{
casID.add(casActon.Case__c);
}
List<Case> casObjLst = [Select Id,Contract_Status__c,Sales_Resubmit_Comments__c,Sales_Resubmission_Date__c,X2nd_Sales_Resubmission_Date__c from Case where Id in : casID];
for(Case_Action__c casActonObj : Trigger.new)
{
Case_Action__c casActnOld = new Case_Action__c();
casActnOld = casActonMap.get(casActonObj.Id);
if(casActonObj.Status__c == 'Resubmitted' && casActnOld.Status__c != 'Resubmitted')
{
for(case cas :casObjLst)
{
//Count = 0;
system.debug('cas.Sales_Resubmission_Date__c----'+cas.Sales_Resubmission_Date__c);
system.debug('cas.X2nd_Sales_Resubmission_Date__c------'+cas.X2nd_Sales_Resubmission_Date__c);
system.debug('Count----'+Count);
if(Count == 0 && cas.Sales_Resubmission_Date__c == null)
{
System.debug('Checking if entering into the loop-------');
cas.Contract_Status__c = 'Resubmitted';
cas.Sales_Resubmit_Comments__c = casActonObj.Resubmit_Comments__c;
cas.Sales_Resubmission_Date__c = System.now();
Count++;
system.debug('Count--1--'+Count);
casLst.add(cas);
}
else if( count == 1 && cas.Sales_Resubmission_Date__c != null)
{
system.debug('Count--2--'+Count);
System.debug('Checking else entering into the loop----1---');
cas.Contract_Status__c = 'Resubmitted';
cas.Sales_Resubmit_Comments__c = casActonObj.Resubmit_Comments__c;
cas.X2nd_Sales_Resubmission_Date__c = System.now();
casLst.add(cas);
}
Count++;
}
}
}
system.debug('Count--3--'+Count);
//Count++;
system.debug('Count--4--'+Count);
system.debug('casLst------'+casLst);
update casLst;
}
Thank You.
Remove the count logic and try, that would work.