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
Mrityunjay Patel 18Mrityunjay Patel 18 

how to get the specific id only without using loop in list

List<order> odr = [select id,odname from order where odname =:'xyz'];
                    if(odr.size() > 0 && insodr.id != null)
                    {
                        for(order od:odr)
                        {
                         od.OpportunityId = insodr.id;
                         update od;
                        }
                         
                    }
 
ankit bansalankit bansal
Hi Mritunjay,
The above code wil not work since you are trying to update order id in the opportunity lookup, but if you dont want to loop put a where condition on the id in the soql itself otherwise you have to loop.
Suraj Tripathi 47Suraj Tripathi 47
Hi Mrityunjay Patel 18

You have to add any unique field in the query if you have. Because in your query might be possible there are multiple records on the same name, so please add the Unique field and query on that and try to add more fields name in the query if in the record any unique value.

Please mark it as the best answer, if it helps in any way.
Thanks!