function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vanessavanessa 

system.out in a trigger

Hy. I'm new on Triggers and apex.

I want to know if i can use system.out.println to do this (part of my code) or on trigger i can't make it out a different message that the system message

 

if(pr.preco__c != 0){
     o.UnitPrice = pr.preco__c;}
 else {
  System.out.println("O Produto não tem preço de referência carregado!:" + p.Description );

 }
}

 

Can help me please? thanks

imuinoimuino

No you cant do that on that on Apex. Why are you trying to do that?

vanessavanessa

 

 

this is my code:

 

trigger InserirPrecoReferencias on OpportunityLineItem (before insert, before update) {

 for (OpportunityLineItem o : Trigger.new)
 {
 Product2 p =
  [select Description from Product2
  where
  id =:o.n_produto_opp__c
 
 ];
  Preco_de_Referencia__c pr = 
  [select preco__c from Preco_de_Referencia__c
  where 
  produto__c = :o.n_produto_opp__c AND
  Condicoes_de_Expedicao__c = :o.Condicoes_de_Expedicao__c AND
  Tipo_de_Preco_de_Referencia__c = :o.Tipo_de_Preco_de_Referencia__c AND
  Valido_ate__c >= today AND
  Valido_de__c <= today 
  
  ];
 if(pr.preco__c != 0){
     o.UnitPrice = pr.preco__c;}
 else {
  o.addError('O Produto não tem preço de referência carregado!:' + p.Description );



 }
}
 
vanessavanessa

this code update Unit Price of OpportunityLineItem with the price of Precos_de_referencia.

 

when failed, the SF return a message than the user doesnt understand, then i want to make it out a other message when preco is null