  We study conditions under which $P(S_\tau>x)\sim P(M_\tau>x)\sim E\tau P(\xi_1>x)$ as $x\to\infty$, where $S_\tau$ is a sum $\xi_1+...+\xi_\tau$ of random size $\tau$ and $M_\tau$ is a maximum of partial sums $M_\tau=\max_{n\le\tau}S_n$. Here $\xi_n$, $n=1$, 2, ..., are independent identically distributed random variables whose common distribution is assumed to be subexponential. We consider mostly the case where $\tau$ is independent of the summands; also, in a particular situation, we deal with a stopping time.   Also we consider the case where $E\xi>0$ and where the tail of $\tau$ is comparable with or heavier than that of $\xi$, and obtain the asymptotics $P(S_\tau>x) \sim E\tau P(\xi_1>x)+P(\tau>x/E\xi)$ as $x\to\infty$. This case is of a primary interest in the branching processes.   In addition, we obtain new uniform (in all $x$ and $n$) upper bounds for the ratio $P(S_n>x)/P(\xi_1>x)$ which substantially improve Kesten's bound in the subclass ${\mathcal S}^*$ of subexponential distributions. 
Asymptotics of randomly stopped sums in the presence of heavy tails