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
mavsmavs 

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); }

 

 

 

SuperfellSuperfell

insert a;

system.debug(a.id);

 

if the insert fails, it throws an exception. 

mavsmavs

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
JimRaeJimRae

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 }