+ Start a Discussion
PeterPPeterP 

Trigger to update list of records

Hi,

 

I struggle with a trigger that needs to create new records in an object called POSITION. The records should be created when a record in another object called TRANSACTION are updated or inserted. Then in POSITION I want the field INSTRUMENT to automatically create a record for all instruments that are in the object TRANSACTION (but no duplicates).

 

Can anyone help me with as exemplary code for a trigger? Mine is definitely wrong ;-(

 

trigger UpdatePosition on TRANSACTION__c (after insert, before update, after update) {

Map<ID, TRANSACTION__c> updateMap = new Map<ID, TRANSACTION__C>();

List<POSITION__c> itemList;

set<Id> AllItems = new set<id>();

for(POSITION__c i :itemList){

AllItems.add(i.TRANSACTION__c);

List<TRANSACTION__C> AllTransactions = [SELECT id, INSTRUMENT__c

                   FROM TRANSACTION__C where id in :AllItems];

SFDC_nkmSFDC_nkm

what u want??

Just tell me clearly.After that only i solve ur problem.

 

PeterPPeterP

Whenever a new record is created in my object "transaction" for a specific product, i want the system to automatically  update my products in stock in my object "positions". If the transaction refers to a product that has never been in stock before, I want the system to create a new record in my object "positions" with an initial stock equal to the transaction amount.

 

In short, a change in one object record shall trigger create new record/update existing record in a different object.

 

I hope this makes it clearer. Thanks for your help.