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

Asset trigger not working, SObject Type is not "Asset", but customized
I had tried different triggers on Assets, however, none of them works. Even simple 'before insert' trigger. Then I did a simple workflow, it worked, however, for my requirements, simple workflow does not work. I need to update a value on Account which is parents of Assets, the value need to come from most recent date value from latest created Asset.
I created my triggers under the standard object 'Asset', triggers. The only thing i noticed here is after i created the trigger, the sobject on top of the trigger section from is not 'Assets', which is different than other objects is
Not sure why it is not “Assets”. Do you have any ideas of how to make this trigger work?
Apex Trigger Detail
Sobject Type: Assets Owned - Epicor
Code below:
trigger MaintenanceExpiration on Asset (after insert) {
Set<ID> acctId = new Set<ID>();
for(Asset ass: Trigger.new) {
acctId.add(ass.Account.id);
}
List<Account> acctList=[SELECT id, Maintenance_Expiration__C from Account where id in :acctId];
for(Asset ass: Trigger.new) {
for( Account a: acctList){
if (ass.Account.id==a.Id){
if (a.Maintenance_Expiration__C==null){
Datetime epday = trigger.new[i].Maintenance_Expiry_Date__c;
a.Maintenance_Expiration__C= date.newInstance(epday.year(), epday.month(),epday.day());
}
else if(a.Maintenance_Expiration__C<trigger.new[i].Maintenance_Expiry_Date__c){
Datetime epday = trigger.new[i].Maintenance_Expiry_Date__c;
a.Maintenance_Expiration__C= date.newInstance(epday.year(), epday.month(),epday.day());
}
}
}
}
if(acctList!=null && acctList.size()>0){
//update account list;
update acctList;
}
}
I created my triggers under the standard object 'Asset', triggers. The only thing i noticed here is after i created the trigger, the sobject on top of the trigger section from is not 'Assets', which is different than other objects is
Sobject Type | Assets Owned - Epicor |
Not sure why it is not “Assets”. Do you have any ideas of how to make this trigger work?
Apex Trigger Detail
Sobject Type: Assets Owned - Epicor
Code below:
trigger MaintenanceExpiration on Asset (after insert) {
Set<ID> acctId = new Set<ID>();
for(Asset ass: Trigger.new) {
acctId.add(ass.Account.id);
}
List<Account> acctList=[SELECT id, Maintenance_Expiration__C from Account where id in :acctId];
for(Asset ass: Trigger.new) {
for( Account a: acctList){
if (ass.Account.id==a.Id){
if (a.Maintenance_Expiration__C==null){
Datetime epday = trigger.new[i].Maintenance_Expiry_Date__c;
a.Maintenance_Expiration__C= date.newInstance(epday.year(), epday.month(),epday.day());
}
else if(a.Maintenance_Expiration__C<trigger.new[i].Maintenance_Expiry_Date__c){
Datetime epday = trigger.new[i].Maintenance_Expiry_Date__c;
a.Maintenance_Expiration__C= date.newInstance(epday.year(), epday.month(),epday.day());
}
}
}
}
if(acctList!=null && acctList.size()>0){
//update account list;
update acctList;
}
}

Hey Jenny, are you able to try something like this?

Thank you. It is working now. I found the Soject Type does not matter here.