The ex date is the relevant date. On this date, you can sell the shares and get the divi.
The record date is different because it takes X days for a trade to settle. It used to be 3 days but has been shortened to 2 in many places.
So if you sell on the day before the ex-dividend date, you won't get the dividend because you won't be marked as the owner on the record date. If you sell on the ex date or after, you will be marked as owner on the record date. Easy, right?!
I think you have your terminology switched.
If you go to the Vanguard link I provided above for VTI, the record date is the date you have to own it to get the dividend, but for VTI the record date reliably is *after* the ex-dividend date.
I can't see any way to reconcile your post with Vanguard's link, so either I misunderstood you or one of us is mistaken. I typically bet on it being the other person, but perhaps that is hubris on my part.
The record date is after the ex date, always, yes. Because it takes time for the trade to settle.
Ex date is the 2nd of a month. Which means you sell on the 2nd. The trade doesn't settle until a number of days later which depends on the exchange, but let's say two. So you sell in your brokerage on the 2nd, the ex date. On the record date two days later you are still the owner because the trade hasn't settled. You are recorded as the owner, you get the dividend.
It's the same with margin. AFAIK you don't start paying a margin loan until the trade settles because you aren't
technically the owner, you haven't actually borrowed the money, until the trade settles.
So - in terms of the dividend, it is the ex-dividend date that matters to you. The record date is not relevant. The only reason the ex date exists is precisely because it takes some number of days for the trade to settle.
Hopefully that's clearer.