Define an $n$-variable function with $n$ undefined?
You can do this:
sum = Sum[i*Indexed[x, i], {i, 1, n}]
D[sum, Indexed[x, 5]]
(* Piecewise[{{5, n >= 5}}, 0] *)
If you have your function take in a list, so you can deal with arbitrary length inputs...
ff[lst_?ListQ] := Total@lst
Then you can do
xs = Array[x, 5]
(* {x[1], x[2], x[3], x[4], x[5]} *)
D[ff[xs], x[4]]
(* 1 *)
D[ff[xs], x[40]]
(* 0 *)
Slightly more complicated
gg[lst_?ListQ] := Times @@ lst
D[gg[xs], x[1]]
(* x[2] x[3] x[4] x[5] *)