+ Start a Discussion

Object Id after Insert

I know this is simple....not sure where i am doing wrong. Any input???


Basically i need the accountid that is just created.


Account a=new Account(); a.type='New'; a.Phone='1234567890'; insert a; if(a.isSuccess) { System.debug(a.getId); }





insert a;



if the insert fails, it throws an exception. 


Thanks simon.


So we cant check if the insert is success or failure.


ok i will add some exception handling.

Message Edited by mavs on 03-17-2010 12:59 PM

Wrap it in a try catch block or use the database insert method if you need to verify success.



try{ insert a; }catch(DMLException e){ //TODO Error handling }



Database.saveresult sr = database.insert(a); if(sr.isSuccess()){ //process for success }