• ifitwalazambia1.3879265308021304E12
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
HI,
I have an object "Financial_Transaction__c" and I create an instance of that object, it triggers the creation of 2 instances of the object "Accounting_Move__c".

Now I don't know how to proceed if I want to update the transaction, so that it updates as well the accounting_move without creating new one.


trigger FinancialTransaction on Financial_Transaction__c (after insert) {
  
        List<Accounting_Move__c> listaccountingmove = new List<Accounting_Move__c>();
   
        for (Financial_Transaction__c ofintran : trigger.New) {
           
                Accounting_Move__c oAccounting_Move = new Accounting_Move__c();
                oAccounting_Move.Accounting_Move_Date__c = ofintran.Date__c;
                oAccounting_Move.Accounting_Move_Description__c = ofintran.Transaction_Description__c;
                oAccounting_Move.Financial_Transaction__c = ofintran.Id;
                          
                Accounting_Move__c oAccounting_Move2 = oAccounting_Move.clone();
               
                oAccounting_Move.From_Account__c = ofintran.From_Account__c;
                oAccounting_Move.Transfer_Account__c = ofintran.To_Account__c;
                oAccounting_Move.Transaction_Amount__c = - ofintran.Transaction_Amount__c;
                listaccountingmove.add(oAccounting_Move);
               
                oAccounting_Move2.From_Account__c = ofintran.To_Account__c;
                oAccounting_Move2.Transfer_Account__c = ofintran.From_Account__c;
                oAccounting_Move2.Transaction_Amount__c = ofintran.Transaction_Amount__c;
                listaccountingmove.add(oAccounting_Move2);
               
         }
         insert listaccountingmove;


I know I need {after update}, then I need to find first the Id of the accounting_Move created?  That's when I'm stuck, should I put the SELECT before or after the for?  I've tried a few things, but I always get errors?

Thanks for your advices.


I'd like to create a trigger that automatically assign a value to a lookup field.
I've tried to emulate what I've read on these 3 posts (but without success)

https://developer.salesforce.com/forums?id=906F000000094NcIAI; How to Give Default value to a LookUp field in salesforce; Trigger based on Record Type + Default Value + Lookupfield;

Here is the situation. I have a Product_Sale__c object. Sale_Account_c is a lookup field in that object. That field is looking up for the Name (the Id?) of an account on Account_c. One of the account on Account__c is 'Sales_Revenue'. I'd like that account to be the default one on Sale_Account__c.

Here is what I wrote:

trigger ProductSale_Default_SaleAccount on Product_Sale__c (before insert, before update) {
             Account__c defaultSaleAcc = [SELECT Name FROM Product_Sale__c WHERE Name='Sales Revenue'];
            for (Product_Sale__c productsale : trigger.new) {
                        productsale.Sale_Account__c = defaultSaleAcc.Name;
            }
}

And I get this error: Compile Error: Illegal assignment from LIST to SOBJECT:Account__c at line 3 column 9

Any advices?
HI,
I have an object "Financial_Transaction__c" and I create an instance of that object, it triggers the creation of 2 instances of the object "Accounting_Move__c".

Now I don't know how to proceed if I want to update the transaction, so that it updates as well the accounting_move without creating new one.


trigger FinancialTransaction on Financial_Transaction__c (after insert) {
  
        List<Accounting_Move__c> listaccountingmove = new List<Accounting_Move__c>();
   
        for (Financial_Transaction__c ofintran : trigger.New) {
           
                Accounting_Move__c oAccounting_Move = new Accounting_Move__c();
                oAccounting_Move.Accounting_Move_Date__c = ofintran.Date__c;
                oAccounting_Move.Accounting_Move_Description__c = ofintran.Transaction_Description__c;
                oAccounting_Move.Financial_Transaction__c = ofintran.Id;
                          
                Accounting_Move__c oAccounting_Move2 = oAccounting_Move.clone();
               
                oAccounting_Move.From_Account__c = ofintran.From_Account__c;
                oAccounting_Move.Transfer_Account__c = ofintran.To_Account__c;
                oAccounting_Move.Transaction_Amount__c = - ofintran.Transaction_Amount__c;
                listaccountingmove.add(oAccounting_Move);
               
                oAccounting_Move2.From_Account__c = ofintran.To_Account__c;
                oAccounting_Move2.Transfer_Account__c = ofintran.From_Account__c;
                oAccounting_Move2.Transaction_Amount__c = ofintran.Transaction_Amount__c;
                listaccountingmove.add(oAccounting_Move2);
               
         }
         insert listaccountingmove;


I know I need {after update}, then I need to find first the Id of the accounting_Move created?  That's when I'm stuck, should I put the SELECT before or after the for?  I've tried a few things, but I always get errors?

Thanks for your advices.