I am currently in the process of trying to get a trigger that will create a new contract each time an asset is created (within a certain product family) When our salesforce was setup our consultant decided against using normal assets and setup a new object for assets hence the custom asset object.
I have managed to create the trigger to create the contract but the problem i am encountering is getting the trigger to link the newly created asset and contract together.
Below is a the code im using any help would be appreciated!
Thanks
trigger create_contract_from_custom_asset on Asset_Custom__c (before insert) {
for(Asset_Custom__c a: trigger.new){
If(a.Product_Family__c <> 'Consumables' && a.Product_Family__c <> 'Hardware'){
string newasId = a.id;
Contract[] Con = new Contract[]{};
Contract c = new Contract();
c.AccountId = a.Account__c;
c.StartDate = a.Purchase_Date__c;
c.Asset__c = a.name;
con.add(c);
Insert con;
}
} }
newasId
or justa.id
, likec.asset__c = a.id;