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
ran67ran67 

how to caught the exception when removing the catch block

Hi ..

 

try{
 opportunity o=[select id from opportunity where name='xxx'];
}
catch(exception e)
{}
now i need to caught the exception
when trigger fails
how to catch and display when records are not getting
while executing the trigger
 
thanks in advance
mohimohi

apexpages.hasMessages can you try this, if this solve your issue, please mark as accepted

SRKSRK
for(integer i = 0 ; i< trigger.new.size() ; i++)
try
{
 list<opportunity> o=[select id from opportunity where name='xxx'];     
 if(o.size() == 0)
      trigger.new[i].adderror(''No Opp Record present with name as xxx');     
}
catch(exception e)
{
    trigger.new[i].adderror('Exception while fatching record' + e);
}
// As u write opportunity o=[select id from opportunity where name='xxx'];  it will not trow any exception if it won't get any reocrd in selct query until & unless u try to use the "o" obj of opp like o.id