'how to get ID of inserted record

I can't seem to figure out how I can get access to the Id of inserted record for Case. I am not sure what I am doing wrong. Any help will be appreciated.

for(Id c: caseMap.keySet())
            {
                      case c1 = new case();
                      c1.Type = 'Routine Maintenance';
                      c1.Status = 'New';
                      c1.OldCaseId__c = c;
                      c1.Vehicle__c = caseMap.get(c).Vehicle__c;
                      c1.Subject  = 'New Maintenence Request for Existing Vehicle';
                      c1.Date_Reported__c = Date.today();
                      If(maintCycles.containskey(c)){
                        c1.Date_Due__c = Date.today().addDays((Integer) maintCycles.get(c));
                      } 
                    newCaselist.add(c1);

             } 
      
            if (newCaselist.size() > 0) {
//get the Id of this new record 
                insert newCaselist;   
            }
            
            
            
            for(Id c: caseMap.keySet()){
                for(Equipment_Maintenance_Item__c eL : equipList){
                    If(eL.Maintenance_Request__c ==  c){
                        Equipment_Maintenance_Item__c e = eL.clone(false, false, false, false);
                                                   
                        e.Maintenance_Request__c = newCaselist.get(c.Id);  //use that Id here 
                        emiList.add(e);  
                    }     
                }
                
            }//end of for loop


Solution 1:[1]

I figured it out by using loop after insert.

for(case nc: newCaselist ) {
    newMapcaseId.put(nc.OldCaseId__c, nc.Id);
    //System.debug('printing map' + newMapcaseId);
}

Then I used newMapcaseId.get(c); to retrieve the Id.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andronicus