• Csaba Czimer
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi All,
I have a question regarding the trigger below. I would like to update the price of a new order when created, ideally from a relationship field.
In the below code, first,  I tried to set the price to 10. If I use the below code, I don't receive an error, however when creating a new order, the price is filled with zero.
However if I don't use the below SOQL query, just write the "for" cycle for the "neworder" list, then it fills the price as expected.
I would like to use the relationship price, though, for which I suspect I need the SOQL query.
Could someone help how to achieve this?

Thanks,
Csaba


trigger setPrice on Order__c (before insert) {
       Order__c[] neworder = Trigger.new;
       for (Order__c ord :[SELECT Order__c.Name, Order__c.Unit_Price__c, Order__c.Product_Name__r.Name ,    Order__c.Product_Name__r.Unit_Price__c
                           FROM Order__c
                           WHERE Order__c.Id IN :neworder]) {

           ord.Unit_Price__c = 10;
                        
       }
    }

 
Hi All,
I have a question regarding the trigger below. I would like to update the price of a new order when created, ideally from a relationship field.
In the below code, first,  I tried to set the price to 10. If I use the below code, I don't receive an error, however when creating a new order, the price is filled with zero.
However if I don't use the below SOQL query, just write the "for" cycle for the "neworder" list, then it fills the price as expected.
I would like to use the relationship price, though, for which I suspect I need the SOQL query.
Could someone help how to achieve this?

Thanks,
Csaba


trigger setPrice on Order__c (before insert) {
       Order__c[] neworder = Trigger.new;
       for (Order__c ord :[SELECT Order__c.Name, Order__c.Unit_Price__c, Order__c.Product_Name__r.Name ,    Order__c.Product_Name__r.Unit_Price__c
                           FROM Order__c
                           WHERE Order__c.Id IN :neworder]) {

           ord.Unit_Price__c = 10;
                        
       }
    }