A corporations primary goal is enacting shareholders wishes. You can talk about stakeholders all you want. It’s bullshit. Companies exist to do what shareholders want, and 9 times out of ten that is make as much money as possible.
There is nothing to say that additional stakeholders cannot be added in by law, though. Companies would dump mercury into the rivers to make a buck if the law didn't prohibit it.
Sure, companies follow the law because it's in their long term best interests and doing otherwise would interfere with their ability to make money down the line.