+ Start a Discussion
vasu takasivasu takasi 

how to get recently inserted record id, i inserted using (controller.save())

hi

i have inserted a record like,

 

ApexPages.StandardController order;
    
    public next_order(ApexPages.StandardController controller)
    {
    order=controller;
    }
    public pagereference next_order()
    {
       
        order.save();

}
}

 

"now i want to get that newly inserted record id"

Best Answer chosen by Admin (Salesforce Developers) 
LVSLVS

you can try order.getId(); after you've performed insert

All Answers

kiranmutturukiranmutturu

i think u need to re query on the object using createddate field ...

 

select id from objectname orderby createddate desc limit 1; this will give recently created record

LVSLVS

you can try order.getId(); after you've performed insert

This was selected as the best answer
kiranmutturukiranmutturu

you can go with  order.getId().. but if any other process may use the order object and may insert order record from any other process too.. then u wont get the recent record ....thats y i opted the query