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
niharnihar 

How to add error message to my class trigger........

public class triggerHelperClass {
public static void updatePostal(List<account> triggerNewList){
   for (Account a: triggerNewList)
   {
   if(a.Match_Billing_Address__c==True)
   {
   a.ShippingPostalCode=a.BillingPostalCode;
   }
   }
}
}
Best Answer chosen by nihar
sfdcMonkey.comsfdcMonkey.com
try this :
public class triggerHelperClass {
public static void updatePostal(List<account> triggerNewList){
   for (Account a: triggerNewList)
   {
   if(a.Match_Billing_Address__c==True)
   {
   a.ShippingPostalCode=a.BillingPostalCode;
   }else{
     a.adderror('Match Billing Address is false');
   }
   }
}
}

 

All Answers

sirajbabu shaiksirajbabu shaik
public class triggerHelperClass {
public static void updatePostal(List<account> triggerNewList){
   for (Account a: triggerNewList)
   {
   if(a.Match_Billing_Address__c==True)
   {
   a.ShippingPostalCode=a.BillingPostalCode;

a.adderror('error');
   }
   }
}
}
sfdcMonkey.comsfdcMonkey.com
try this :
public class triggerHelperClass {
public static void updatePostal(List<account> triggerNewList){
   for (Account a: triggerNewList)
   {
   if(a.Match_Billing_Address__c==True)
   {
   a.ShippingPostalCode=a.BillingPostalCode;
   }else{
     a.adderror('Match Billing Address is false');
   }
   }
}
}

 
This was selected as the best answer
niharnihar
hi piyush,
The above mention code is stasfying only error condition
but not shipping=billing condition...........
sfdcMonkey.comsfdcMonkey.com
sorry but am not getting your point, can you explane it when you have need to display error massage in trigger/apex
niharnihar
the above mention code:
public class triggerHelperClass {
public static void updatePostal(List<account> triggerNewList){
   for (Account a: triggerNewList)
   {
   if(a.Match_Billing_Address__c==True)
   {
   a.ShippingPostalCode=a.BillingPostalCode;
   }else{
   a.adderror('Match Billing Address is false');
   }
   }
}
}  
is taking only error condition (a.adderror('Match Billing Address is false'); )
it is not taking ( a.ShippingPostalCode=a.BillingPostalCode;)
but i want to excute two conditions(  a.ShippingPostalCode=a.BillingPostalCode; && a.adderror('Match Billing Address is false'); )