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

Trigger to change the status of an asset
Hi
I am new to salesforce platform.I need help with triggers.
I have created a look up field in contacts named Assets_owned. whenever a particular asset is selected in assets_owned i want to change the asset status to assigned from the picklist in the assets tab.
Thanks!
Hi ,
Below solution is a simple one, this cannot be used for bulk records updates
trigger updateAssetsOwnedStatus on Contact (after insert, after update) {
//I am assuming the API name of the field on the Contacts as Assets_Owned__c and the Status field as assets_Status__c
if(trigger.new[0].Assets_Owned__c !=null){
Assets_Owned__c assetsOwned = [select id, assets_status__c from assets_owned__c where id=:trigger.new[0].Assets_Owned__c];
assetsOwned.assets_status__c = 'Assigned';
update assetsOwned;
}
}
Hope this helps!
Regards
Sameer
All Answers
Hi ,
Below solution is a simple one, this cannot be used for bulk records updates
trigger updateAssetsOwnedStatus on Contact (after insert, after update) {
//I am assuming the API name of the field on the Contacts as Assets_Owned__c and the Status field as assets_Status__c
if(trigger.new[0].Assets_Owned__c !=null){
Assets_Owned__c assetsOwned = [select id, assets_status__c from assets_owned__c where id=:trigger.new[0].Assets_Owned__c];
assetsOwned.assets_status__c = 'Assigned';
update assetsOwned;
}
}
Hope this helps!
Regards
Sameer
Thanks a lot sameer it worked!!
I also want to change the asset status as Instock when it is deleted from that particular contact or i update the contact with another asset.
trigger updateAssetsOwnedStatus on Contact (after insert, after update) {
//I am assuming the API name of the field on the Contacts as Assets_Owned__c and the Status field as assets_Status__c
if(trigger.new[0].Assets_Owned__c !=null){
Assets_Owned__c assetsOwned = [select id, assets_status__c from assets_owned__c where id=:trigger.new[0].Assets_Owned__c];
assetsOwned.assets_status__c = 'Assigned';
update assetsOwned;
}
if( trigger.isUpdate && trigger.old[0].assets_owned__c !=null && trigger.old[0].assets_owned__c != trigger.new[0].Assets_Owned__c){
Assets_Owned__c assetsOwnedOld = [select id, assets_status__c from assets_owned__c where id=:trigger.old[0].Assets_Owned__c];
assetsOwnedOld.assets_status__c = 'Instock';
update assetsOwnedOld;
}
}
I think this will work, Please try it out. Again this cannot be used for bulk records.
Regards
Sam
how to create a trigger that updates the asset status to cancelled when the account is cancelled