Consider a plant like Aloe Vera that grows up in a toxic environment where the concentration of pesticides, and materials like lead, mercury, cadmium, arsenic etc is very high(e.g. Marshland dumping yard ). Would that mean that the extract from these plants would contain all these toxic elements.
Not "all of them". But yes, plants suck up water from the soil, with everything dissolved in this water - nutrients, heavy metals, poisons. And also they breathe air, and absorb stuff via this route.
There probably are some toxins which will not enter the plant, because their molecules are too large and/or fragile. For example, should a plant root come in contact with snake venom, I cannot imagine that any venom will end up stored in the plant leaves.
Plants also have their own metabolism, so they will change/deactivate some toxins. I've seen claims that some plants "purify" formaldehyde, although I don't trust the sources enough to be sure of that.
But the smaller the poison molecule, and the less similar to stuff which is usually digested in nature, the more likely that it will enter the plant and stick around instead of being broken down. The heavy metals you mentioned are prime candidates. If they are present in the groundwater - or also lead from air pollution, before we banned leaded gasoline - they end up in plants, including food plants. And mushrooms are even more at risk.
Growing food near waste dumps is a known problem in farming, and sometimes makes the news, for example here: http://bigstory.ap.org/article/mafia-toxic-waste-dumping-poisons-italy-farmlands