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
VINODKUMAR REDDY KALUVAVINODKUMAR REDDY KALUVA 

How can I avoid nested for loop in the below code?

Can anyone help on avoiding nested for loop in the below code:
List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name LIKE :Liktr];
    System.debug('leadAccountIds=' + leadAccountIds);

    Map<String, Id> acctNameId=new Map<String, Id>();
    Map<String, Id> acctNameOwner=new Map<String, Id>();
    if(leadAccountIds.size()==1){
          For (Account a :leadAccountIds){

                  acctNameId.put(a.name,a.Id);
                  acctNameOwner.put(a.name,a.ownerId);
                  system.debug(acctNameOwner);
                  system.debug(acctNameId);

                For (Lead l2:trigger.new){
                         l2.ownerId=a.ownerId;
                         system.debug(a.ownerId);
                 }
           }
Thanks in advance!....
 
Prema -Prema -
You can use List<Lead> l2=[select  ownerId from Lead WHERE ID IN: Trigger.new]