You need to sign in to do that
Don't have an account?

Class.ActTrigger.AccUpdateDateOfAssignment: line 141, column 1
public class ActTrigger {
public List<Contact> listContactObj = new List<Contact>(); // List to store the Contacts
public List<Opportunity> listOpportunityObj = new List<Opportunity>();//List to store Opportunities
public List<Contract> listContractObj = new List<Contract>();//List to store Contracts
public List<task> listTaskObj = new List<task>();// List to store Tasks
public List<Event> listEventObj = new List<Event>();// List to store Events
public Set<String> ownerIds = new Set<String>();
public Map<String,Account> managerAccMap = new Map<String,Account>();
public Account[] oldMap = Trigger.old;
public Integer iCount =0;
public String sOwnerId = '';
public ActTrigger (){
}
public void AccRltdObjOwnChangeMethod (Set<Id> accountIds, Map<Id, String> newOwnerIdsMap){
if (!accountIds.isEmpty()) {
//SOQL to get Contact,Contacts, Open Activities and Opportunities for all updated Accounts
for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Contracts),(SELECT Id, OwnerId FROM Opportunities),(SELECT Id, OwnerId,Status__c FROM events where isrecurrence = false and RecurrenceActivityId = null),(SELECT Id, OwnerId,Status FROM tasks where isrecurrence = false and RecurrenceActivityId = null) FROM Account WHERE Id in :accountIds]) {
//Updating Contact Owner with the Accounts New Ownerrelated to the Account
for (Contact c : act.Contacts ) {
c.OwnerId=newOwnerIdsMap.get(act.id);
listContactObj.add(c);
}
//Updating Contract Owner with the Accounts New Owner related to the Account
for (Contract c : act.Contracts) {
c.OwnerId=newOwnerIdsMap.get(act.id);
listContractObj.add(c);
}
//Updating Opportunity Owner with the Accounts New Owner related to the Account
for (Opportunity o : act.Opportunities) { //for all opportunities
o.OwnerId =newOwnerIdsMap.get(act.id);
listOpportunityObj.add(o);
}
//Updating Open Tasks Owner with the Accounts New Owner related to the Account
for (task t : act.tasks) {
if(t.status=='Open' || t.status == 'Scheduled'){
t.OwnerId =newOwnerIdsMap.get(act.id);
listTaskObj.add(t);
}
}
//Updating Open Events Owner with the Accounts New Owner related to the Account
for (Event e : act.events) {
if(e.status__c=='Pending' || e.status__c == 'Scheduled'){
e.OwnerId =newOwnerIdsMap.get(act.id);
listEventObj.add(e);
}
}
System.debug('$$$$$Events List'+listEventObj);
}
try {
update listContactObj;
update listContractObj;
update listOpportunityObj;
update listTaskObj;
update listEventObj;
}
catch(Exception e) { //catch errors
}
}
}
public void AccRltdObjOwnChangeMethodBENDACH(Set<Id> accountIdsBENDACH, Map<Id, String> newOwnerIdsMapBENDACH){
if (!accountIdsBENDACH.isEmpty()) {
//SOQL to get Contact,Contacts for all updated Accounts
for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Contracts),(SELECT Id, OwnerId FROM Opportunities),(SELECT Id, OwnerId,Status__c FROM events where isrecurrence = false and RecurrenceActivityId = null),(SELECT Id, OwnerId,Status FROM tasks where isrecurrence = false and RecurrenceActivityId = null) FROM Account WHERE Id in :accountIdsBENDACH]) {
//CR-20 Updating Contact Owner with the Accounts New Ownerrelated to the Account on 28-05-2013
for (Contact c : act.Contacts ) {
c.OwnerId=newOwnerIdsMapBENDACH.get(act.id);
listContactObj.add(c);
}
//CR-18 Updating Contract Owner with the Accounts New Owner related to the Account on 28-05-2013
for (Contract c : act.Contracts) {
c.OwnerId=newOwnerIdsMapBENDACH.get(act.id);
listContractObj.add(c);
}
}
try {
update listContactObj;
update listContractObj;
}
catch(Exception e) { //catch errors
}
}
}
Public Void AccUpdateDateOfAssignment(Map<ID,Boolean> AccounUpdateMap,List<account> NewAccountList){
try{
List<Account> accountUpdateList = New List<Account>();//list of accounts whose date of assignment is to be changed
Set<ID> accOwnerNotchangedSet = New Set<ID>();//Account whose owners have not been changed
Map<ID,Date> OwnercreatedDate = New Map<ID,Date>();//this is used to track the latest owner change date
List<Date> CreatedDates = New List<Date>();
Set<ID> AccupdateDoASet = New Set<ID>();
Map<ID,Date> AccupdateNewCustomerMap = New Map<ID,Date>();
for(Account accountList:[Select New_Customer__c,id,Date_Of_Assignment__c,Last_Successful_Call_Date__c from account where id IN:AccounUpdateMap.keySet()]){
if(AccounUpdateMap.get(accountList.id)== True){
AccupdateDoASet.add(accountList.id);
}
else
accOwnerNotchangedSet.add(accountList.id);
}
/*Iterate through owner change history to find the last date of assignment*/
141: for(account acclIst: [select id,Last_Successful_Call_Date__c,New_Customer__c, (select CreatedDate,OldValue, NewValue,field,AccountId from Histories) FROM account where id IN:accOwnerNotchangedSet]){
for(AccountHistory accHis:acclIst.Histories){
if(accHis.field == 'owner')
CreatedDates.add(Date.valueof(accHis.CreatedDate));
}
If(CreatedDates.size()>0){
CreatedDates.sort();
OwnercreatedDate.put(acclIst.id,CreatedDates[(CreatedDates.size()-1)]);
acclIst.Date_Of_Assignment__c= Date.valueof(CreatedDates[(CreatedDates.size()-1)]);
AccupdateNewCustomerMap.put(acclIst.id,Date.valueof(CreatedDates[(CreatedDates.size()-1)]));
}
}
/*Update the date of assignemtn in account*/
for(account ac:NewAccountList){
if(AccupdateDoASet.contains(ac.id)){
ac.Date_Of_Assignment__c= Date.Today();
}
else if(AccupdateNewCustomerMap.containsKey(ac.id) ){
//ac.Date_Of_Assignment__c = Date.valueof(CreatedDates[(CreatedDates.size()-1)]);
ac.Date_Of_Assignment__c = AccupdateNewCustomerMap.get(ac.id);
}
Date LastSuccessDate ;
Date DateOfAssgn;
DateTime doA = ac.Date_Of_Assignment__c;
if(doA!=null)
DateOfAssgn = date.newinstance(doA.year(), doA.month(), doA.day());
DateTime Lsd = ac.Last_Successful_Call_Date__c;
if(Lsd!=null)
LastSuccessDate = date.newinstance(Lsd .year(), Lsd .month(), Lsd .day());
If(ac.Date_Of_Assignment__c != Null){
if(LastSuccessDate >= DateOfAssgn )
ac.New_Customer__c=False;
}
}
}
catch(Exception e) { //catch errors
}
}
public void AccRepMangUpdateMethod (List<Account> AccIDList){
For(Account Acct : AccIDList){
if(Acct.Lead_Owner_ID__c!=null){
Acct.owner_link__c = Acct.Lead_Owner_ID__c;
Acct.OwnerId = Acct.Lead_Owner_ID__c;
ownerIds.add(Acct.Lead_Owner_ID__c);
if(Acct.Lead_Owner_ID__c.length()>15)
sOwnerId = Acct.Lead_Owner_ID__c.substring(1,15);
else
sOwnerId = Acct.Lead_Owner_ID__c;
managerAccMap.put(sOwnerId+':'+Acct.Id,Acct);
}
else{
Acct.owner_link__c = Acct.ownerId;
ownerIds.add(Acct.ownerId);
system.debug('**Acct.ownerId**'+Acct.ownerId);
if(String.ValueOf(Acct.ownerId).length()>15)
sOwnerId = String.ValueOf(Acct.ownerId).substring(1,15);
else
sOwnerId = Acct.ownerId;
managerAccMap.put(sOwnerId+':'+Acct.Id,Acct);
}
}
if(ownerIds.size() > 0){
Map<String,String> managerMap = new Map<String,String>();
//system.Debug('@@@@@@@@@@@@ownerIds' + ownerIds);
for (User u: [Select id,ManagerId from User where id in : ownerIds]){
//if(u.managerId != null)
if(String.ValueOf(u.id).length()>15)
managerMap.put(String.ValueOf(u.id).substring(1,15),u.ManagerId);
else
managerMap.put(u.id,u.ManagerId);
}
//system.Debug('@@@@@@@@@@@@managerMap' + managerMap);
for(String accId: managerAccMap.keySet()){
//system.Debug('@@@@@@@@@@@@accid' + accid);
String[] sTemp = accid.split(':');
//system.Debug('@@@@@@@@@@@@sTemp ' + sTemp );
if(managerMap.containsKey(sTemp[0]) && managerMap.get(sTemp[0]) !=Null){
(managerAccMap.get(accId)).Rep_manager__c = managerMap.get(sTemp[0]);
}
//system.Debug('@@@@@@@@@@@@(managerAccMap.get(accId)).Rep_manager__c ' + (managerAccMap.get(accId)).Rep_manager__c);
//system.Debug('@@@@@@@@@@@@managerMap.get(sTemp[0] ' + managerMap.get(sTemp[0]));
}
//system.Debug('@@@@@@@@@@@@managerAccMap ' + managerAccMap);
}
}
public void AccRepMangUpdtMethod (List<Account> AccIDList){
For(Account Acct : AccIDList){
acct.owner_link__c = acct.ownerId;
ownerIds.add(acct.ownerId);
if(String.ValueOf(acct.ownerId).length()>15)
sOwnerId = String.ValueOf(acct.ownerId).substring(1,15);
else
sOwnerId = acct.ownerId;
managerAccMap.put(sOwnerId+':'+acct.Id,acct);
}
if(ownerIds.size() > 0){
Map<String,String> managerMap = new Map<String,String>();
//system.Debug('@@@@@@@@@@@@ownerIds' + ownerIds);
for (User u: [Select id,ManagerId from User where id in : ownerIds]){
//if(u.managerId != null)
if(String.ValueOf(u.id).length()>15)
managerMap.put(String.ValueOf(u.id).substring(1,15),u.ManagerId);
else
managerMap.put(u.id,u.ManagerId);
}
//system.Debug('@@@@@@@@@@@@managerMap' + managerMap);
for(String accId: managerAccMap.keySet()){
//system.Debug('@@@@@@@@@@@@accid' + accid);
String[] sTemp = accid.split(':');
//system.Debug('@@@@@@@@@@@@sTemp ' + sTemp );
if(managerMap.containsKey(sTemp[0]) && managerMap.get(sTemp[0]) !=Null){
(managerAccMap.get(accId)).Rep_manager__c = managerMap.get(sTemp[0]);
}
//system.Debug('@@@@@@@@@@@@(managerAccMap.get(accId)).Rep_manager__c ' + (managerAccMap.get(accId)).Rep_manager__c);
//system.Debug('@@@@@@@@@@@@managerMap.get(sTemp[0] ' + managerMap.get(sTemp[0]));
}
//system.Debug('@@@@@@@@@@@@managerAccMap ' + managerAccMap);
}
}
public void CallPlannerMethod (List<Account> AccIDList){
For(Account Acct : AccIDList){
if(acct.CallFrequencyOverride__c != 0 && acct.CallFrequencyOverride__c !=null){
Integer DaystoBeAdded = Integer.valueOf(365/acct.CallFrequencyOverride__c);
for(integer i =0;i<7;i++){
if(math.mod(DaystoBeAdded,7)==0){
break;
}
DaystoBeAdded++;
}
if(acct.Last_Successful_Call_Date__c!=Null)
acct.Next_Call_Date__c = acct.Last_Successful_Call_Date__c + DaystoBeAdded ;
}
else if (acct.Suggested_Call_Frequency__c != 0 && acct.Suggested_Call_Frequency__c !=null){
Integer DaystoBeAdded = Integer.valueOf(365/acct.Suggested_Call_Frequency__c);
for(integer i =0;i<7;i++){
if(math.mod(DaystoBeAdded,7)==0){
break;
}
DaystoBeAdded++;
}
if(acct.Last_Successful_Call_Date__c!=Null)
acct.Next_Call_Date__c = acct.Last_Successful_Call_Date__c + DaystoBeAdded ;
}
}
}
}
Hi,
Can you move the select from inside that for statement to a separate line (List<Account> accList =....)? And use a System.debug('accList has this value' + accList) to show its value?
Ty,
Adrian