You need to sign in to do that
Don't have an account?
Susan Love 2
Use of Sets
HI
I have a trigger written that updates a field on the account page from the contract page but only for certain products. I have this written as a list (in bold) but it is not picking up these products. I have been told to change to a set but I am not familar with sets copy of trigger below can anyone help with this?
Trigger updateESPWorryDate on Contract (after insert, after update)
{
List<Contract> CL=trigger.new;
List<Id> aid=new List<Id>();
for(Contract c: CL)
{
aId.add(c.AccountId);
}
list<Account> AL=new List<Account>();
for(Account a: [select Id from Account where Id in :aId])
{
List<Contract> ICL=[select Status, Sub_End_Date__c from Contract where AccountId=: a.Id];
String max='1900-01-01';
for(Contract c: ICL)
{
List<String> productCodeList = new List<String>{'ESP-E-R','ESP-B-R', 'ESP-B-I', 'ESP-P-R', 'ESP-P-I', 'ESP-E-I'};
{
if(c.Status=='Activated' && c.Sub_End_Date__c !=null)
if(Date.valueOf(max)<c.Sub_End_Date__c)
max=String.valueOf(c.Sub_End_Date__c);
}
if(max!='1900-01-01')
a.ESP_Worry_Date__c=Date.valueOf(max);
AL.add(a);
}
Set<Account> accountData = new Set<Account>(AL);
AL=new List<Account>(accountData);
if(AL.size()>0)
update AL;
}
}
I have a trigger written that updates a field on the account page from the contract page but only for certain products. I have this written as a list (in bold) but it is not picking up these products. I have been told to change to a set but I am not familar with sets copy of trigger below can anyone help with this?
Trigger updateESPWorryDate on Contract (after insert, after update)
{
List<Contract> CL=trigger.new;
List<Id> aid=new List<Id>();
for(Contract c: CL)
{
aId.add(c.AccountId);
}
list<Account> AL=new List<Account>();
for(Account a: [select Id from Account where Id in :aId])
{
List<Contract> ICL=[select Status, Sub_End_Date__c from Contract where AccountId=: a.Id];
String max='1900-01-01';
for(Contract c: ICL)
{
List<String> productCodeList = new List<String>{'ESP-E-R','ESP-B-R', 'ESP-B-I', 'ESP-P-R', 'ESP-P-I', 'ESP-E-I'};
{
if(c.Status=='Activated' && c.Sub_End_Date__c !=null)
if(Date.valueOf(max)<c.Sub_End_Date__c)
max=String.valueOf(c.Sub_End_Date__c);
}
if(max!='1900-01-01')
a.ESP_Worry_Date__c=Date.valueOf(max);
AL.add(a);
}
Set<Account> accountData = new Set<Account>(AL);
AL=new List<Account>(accountData);
if(AL.size()>0)
update AL;
}
}
ok
susan
trigger updateAccount on contract(after insert, after update)
{
List<Contract> CL=trigger.new;
List<Id> aid=new List<Id>();
for(Contract c: CL)
{
aId.add(c.AccountId);
}
list<Account> AL=new List<Account>();
for(Account a: [select Id from Account where Id in :aId])
{
List<Contract> ICL=[select Status, Sub_End_Date__c from Contract where AccountId=: a.Id];
String max='1900-01-01';
for(Contract c: ICL)
{
if(c.Status=='Activated' && c.Sub_End_Date__c !=null)
if(Date.valueOf(max)<c.Sub_End_Date__c)
max=String.valueOf(c.Sub_End_Date__c);
}
if(max!='1900-01-01')
a.Worry_Date__c=Date.valueOf(max);
AL.add(a);
}
if(AL.size()>0)
update AL;
}
We now have new products we wish to monitior on the Account page we have another field named a.ESP_Worry_Date__c and from the Contract page when the c.Sub_End_Date__c field is updated and the prouducts are either 'ESP-E-R','ESP-B-R', 'ESP-B-I', 'ESP-P-R', 'ESP-P-I', 'ESP-E-I' then the a.ESP_Worry_Date__c has to be completed on the Account page. However if the products are 'SUBS-I', 'IMP', 'SUBS-R' then the a.Worry_Date__c has to be completed on the Account page.
Hope this makes sense.
Thanks
Susan