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
URVASHIURVASHI 

Apex code

Can anyone help.

If i am doing an operation of inserting some values in an object using a loop.

Account a=new Account();
for(Integer j=0;j<5;j++)
 {
 a.put(l[j],inputvalues[j]);
 }  
Here inputvalues and l array contains the following values:
l[j]                inputvalues[j]
Name                 Neha 
Accountnumber        5023   

If suppose there occurs some error during "put" operation then i get the error in Visual Force page
Instead of this i want an error in some other resource like a variable or list item and my operation of insert should not stop.
Anyone has a solution to this.
Please help with some sample code.

 

Thanks.

harshasfdcharshasfdc

hi ,

 

try mapping the field of account.

eg

 

Account a=new Account();
for(Integer j=0;j<5;j++)
{
a.name=d;
}

 

thanks,

Harsha

Avidev9Avidev9

Well you can always catch the errors using try catch

 

for(Integer j=0;j<5;j++)
 {
     try{
a.put(l[j],inputvalues[j]);
}
catch(exception ex){
//whenever there will be an error execution will come here and the loop will not stop
} }