For example, $\frac{4}{(x-2)(x+7)} = \frac{A}{x+7} + \frac{B}{x-2}$
setting the numerator: $4= A(x-2) + B(x+7) $
The method I always use is to expand and compare coefficients, which can be very long if it is a more complicated fraction.
However, to solve this very quickly, we can take $x=2$ and therefore $A = -4/9$
and $x= -7$ and therefore $B=4/9$
What is this trick and when can I use it? I've not learnt this, but I've seen many people do this trick to solve integral partial fractions very quickly. Can I get some examples on when can I use it and how to determine it as I've heard that we cannot use this for every situation.
For partial fractions, I've learnt about
Linear: $Q(x) = ax+b : \frac{A}{ax+b}$
Irreducible/Quadratic: $Q(x) = ax^2 + bx+c : \frac{Ax+B}{ax^2 +bx+c}$
I don't know a name for the trick. The original equation comes with a hidden $x \neq 2,-7$ because of the denominator so you are technically taking the limit as $x \to 2$. You got it backwards in your post-when you substitute in $x=2$ you get the value for $B$ because the $A(x-2)$ goes to zero.
Another way would be to substitute any two other values for $x$. You would get two simultaneous equations for $A,B$. Using $2,-7$ is convenient because the equations decouple.