Independently derived solution.
Use 35 equal units for the original number of fruits. Apples make up 1/5 = 7/35 of the total. Apples sold make up 4/7 × 1/5 = 4/35 of the total, or 4 units.
Since 2/5 of the fruits remain, 3/5 = 21/35 were sold, or 21 units. The oranges sold therefore represent 21 − 4 = 17 units. These are the 51 oranges, so 1 unit = 51 ÷ 17 = 3 fruits. Original total = 35 × 3 = 105 fruits.
Check: there were 21 apples and 84 oranges. She sold 12 apples and 51 oranges, leaving 42 fruits; 42/105 = 2/5. The supplied workings call the oranges “pears”; the question consistently says oranges.