+ 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