Multiple AJAX calls ; get all the failed calls
You would not be able to reliably get all of the failed IDs in the .fail handler because it will fire as soon as any of the deferreds becomes rejected, regardless of the state of the other deferreds.
If you want to keep track of which requests succeeded and which failed, I think your best option would be to attach a catch handler to each $.ajax call that will catch a failure and map it to an object that has a reference to the id and to the success/failure status. Catching errors this way will mean that all of the deferreds will succeed, so the handling of success and failed states will then need to be performed in the done handler attached to the $.when. For example:
var urlId = [1, 3, 4, 7]
let requests = [];

urlId.forEach(id => {
  requests.push(
    $.ajax(/*...*/)
      .then(response => {
        return {
          id,
          success: true,
          response
        };
      })
      .catch(error => {
        return {
          id,
          success: false,
          error
        }
      })
  );
});

$.when.apply($, requests)
  .done(function (values) {
    $.each(arguments, function (idx, obj) {
      console.log(`${obj.id}: success = ${obj.success}`);
    });
 });

Here is a fiddle for reference.

I am making multiple ajax calls as shown below. Below code works fine If all the calls succeed. But, let's say urlId 3 and 4 failed for some reason. Is it possible to get all the failed urlId's in the fail function?
var urlId = [1, 3, 4, 7]
let requests = [];
for (let i = 0; i < urlId.length; i++) {
    requests.push($.ajax(...));
}
$.when.apply($, requests).done(function () {
    $.each(arguments, function (idx, args) {
        //process args : urlId[idx]
    });
}).fail(function (jqXHR) {
    //how to get urlId's failed
});

