You need to sign in to do that
Don't have an account?
wilbur07
Bug!!!!!!!
I think I found a nasty bug in salesforce.
I created AssetHistory object which is supposed to be a replica of CaseHistory object only tracks Asset changes.
When creating the trigger to make the system work I could not assign any values to AssetHistory__c.Asset__r!!!!
Unlike Contact.AccountID which is used to assign a parent Account ID to a contact, I could not assign a value to AssetHistory.AssetID which is an invalid field or any other iteration of the same, Asset__r.Id is not writeable, Asset.ID does
not work, Asset__r= [select id from Asset where id = 'somevalidAssetID'] does not work!!!!!!
None of the Asset references to ID or the sObject Asset instances are stored when I assign Asset__r = <some valid Asset> and then insert the new AssetHistory__c record!!!!!
This has got to be a bug!
Any help of course would be appreciated.
James
I created AssetHistory object which is supposed to be a replica of CaseHistory object only tracks Asset changes.
When creating the trigger to make the system work I could not assign any values to AssetHistory__c.Asset__r!!!!
Unlike Contact.AccountID which is used to assign a parent Account ID to a contact, I could not assign a value to AssetHistory.AssetID which is an invalid field or any other iteration of the same, Asset__r.Id is not writeable, Asset.ID does
not work, Asset__r= [select id from Asset where id = 'somevalidAssetID'] does not work!!!!!!
None of the Asset references to ID or the sObject Asset instances are stored when I assign Asset__r = <some valid Asset> and then insert the new AssetHistory__c record!!!!!
This has got to be a bug!
Any help of course would be appreciated.
James
trigger AddAssetHistory on Asset (after insert, after update) {
for (Asset a : Trigger.new) {
if (Trigger.isInsert) {
AssetHistory__c nli0 = new AssetHistory__c();
nli0.Name='Created';
nli0.Asset__r=a;
insert nli0;
}
else {
if(Trigger.newMap.get(a.Id).Name!=Trigger.oldMap.get(a.Id).Name) {
AssetHistory__c nli = new AssetHistory__c();
nli.Name='Changed Name';
nli.Field__c='Name';
if(Trigger.oldMap.get(a.Id).Name==null) nli.OldValue__c='null';
else nli.OldValue__c=Trigger.oldMap.get(a.Id).Name;
nli.NewValue__c=Trigger.newMap.get(a.Id).Name;
nli.Asset__r=a;;
insert nli;
}
if(Trigger.newMap.get(a.Id).SerialNumber!=Trigger.oldMap.get(a.Id).SerialNumber) {
AssetHistory__c nli2 = new AssetHistory__c();
nli2.Name='Changed Serial Number';
nli2.Field__c='SerialNumber';
if(Trigger.oldMap.get(a.Id).SerialNumber==null) nli2.OldValue__c='null';
else nli2.OldValue__c=Trigger.oldMap.get(a.Id).SerialNumber;
nli2.NewValue__c=Trigger.newMap.get(a.Id).SerialNumber;
nli2.Asset__r=a;
insert nli2;
}
if(Trigger.newMap.get(a.Id).InstallDate!=Trigger.oldMap.get(a.Id).InstallDate) {
AssetHistory__c nli3 = new AssetHistory__c();
nli3.Name='Changed Install Date';
nli3.Field__c='InstallDate';
if(Trigger.oldMap.get(a.Id).InstallDate==null) nli3.OldValue__c='null';
else nli3.OldValue__c=Trigger.oldMap.get(a.Id).InstallDate.format();
nli3.NewValue__c=Trigger.newMap.get(a.Id).InstallDate.format();
nli3.Asset__r=a;
insert nli3;
}
if(Trigger.newMap.get(a.Id).PurchaseDate!=Trigger.oldMap.get(a.Id).PurchaseDate) {
AssetHistory__c nli4 = new AssetHistory__c();
nli4.Name='Changed Purchase Date';
nli4.Field__c='PurchaseDate';
if(Trigger.oldMap.get(a.Id).PurchaseDate==null) nli4.OldValue__c='null';
else nli4.OldValue__c=Trigger.oldMap.get(a.Id).PurchaseDate.format();
nli4.NewValue__c=Trigger.newMap.get(a.Id).PurchaseDate.format();
nli4.Asset__r=a;
insert nli4;
}
if(Trigger.newMap.get(a.Id).UsageEndDate!=Trigger.oldMap.get(a.Id).UsageEndDate) {
AssetHistory__c nli5 = new AssetHistory__c();
nli5.Name='Changed Usage End Date';
nli5.Field__c='UsageEndDate';
if(Trigger.oldMap.get(a.Id).UsageEndDate==null) nli5.OldValue__c='null';
else nli5.OldValue__c=Trigger.oldMap.get(a.Id).UsageEndDate.format();
nli5.NewValue__c=Trigger.newMap.get(a.Id).UsageEndDate.format();
nli5.Asset__r=a;
insert nli5;
}
if(Trigger.newMap.get(a.Id).Status!=Trigger.oldMap.get(a.Id).Status) {
AssetHistory__c nli6 = new AssetHistory__c();
nli6.Name='Changed Status';
nli6.Field__c='Status';
if(Trigger.oldMap.get(a.Id).Status==null) nli6.OldValue__c='null';
else nli6.OldValue__c=Trigger.oldMap.get(a.Id).Status;
nli6.NewValue__c=Trigger.newMap.get(a.Id).Status;
nli6.Asset__r=a;
insert nli6;
}
if(Trigger.newMap.get(a.Id).Price!=Trigger.oldMap.get(a.Id).Price) {
AssetHistory__c nli7 = new AssetHistory__c();
nli7.Name='Changed Price';
nli7.Field__c='Price';
if(Trigger.oldMap.get(a.Id).Price==null) nli7.OldValue__c='null';
else nli7.OldValue__c=Trigger.oldMap.get(a.Id).Price.format();
nli7.NewValue__c=Trigger.newMap.get(a.Id).Price.format();
nli7.Asset__r=a;
insert nli7;
}
if(Trigger.newMap.get(a.Id).Quantity!=Trigger.oldMap.get(a.Id).Quantity) {
AssetHistory__c nli8 = new AssetHistory__c();
nli8.Name='Changed Quantity';
nli8.Field__c='Quantity';
if(Trigger.oldMap.get(a.Id).Quantity==null) nli8.OldValue__c='null';
else nli8.OldValue__c=Trigger.oldMap.get(a.Id).Quantity.format();
nli8.NewValue__c=Trigger.newMap.get(a.Id).Quantity.format();
nli8.Asset__r=a;
insert nli8;
}
if(Trigger.newMap.get(a.Id).Contact.Id!=Trigger.oldMap.get(a.Id).Contact.Id) {
AssetHistory__c nli9 = new AssetHistory__c();
nli9.Name='Changed Contact';
nli9.Field__c='Contact';
if(Trigger.oldMap.get(a.Id).Contact==null) nli9.OldValue__c='null';
else nli9.OldValue__c=Trigger.oldMap.get(a.Id).Contact.Name;
nli9.NewValue__c=Trigger.newMap.get(a.Id).Contact.Name;
nli9.Asset__r=a;
insert nli9;
}
if(Trigger.newMap.get(a.Id).Account.Id!=Trigger.oldMap.get(a.Id).Account.Id) {
AssetHistory__c nli10 = new AssetHistory__c();
nli10.Name='Changed Account';
nli10.Field__c='Account';
if(Trigger.oldMap.get(a.Id).Account==null) nli10.OldValue__c='null';
else nli10.OldValue__c=Trigger.oldMap.get(a.Id).Account.Name;
nli10.NewValue__c=Trigger.newMap.get(a.Id).Account.Name;
nli10.Asset__r=a;
insert nli10;
}
if(Trigger.newMap.get(a.Id).Product2.Id!=Trigger.oldMap.get(a.Id).Product2.Id) {
AssetHistory__c nli11 = new AssetHistory__c();
nli11.Name='Changed Product';
nli11.Field__c='Product2';
if(Trigger.oldMap.get(a.Id).Product2==null) nli11.OldValue__c='null';
else nli11.OldValue__c=Trigger.oldMap.get(a.Id).Product2.Name;
nli11.NewValue__c=Trigger.newMap.get(a.Id).Product2.Name;
nli11.Asset__r=a;
insert nli11;
}
}
}
}
This produces the appropriate AssetHistory records but doesn't record the Asset parent object so nothing shows up in the related list for the Asset when a change is made to the Asset.
If you could give me a way to do this it would solve my problem.
James
Thanks for the help!
James