And after the foreclosure sale?
It depends. That's helpful, isn't it?
First, once you've found the Notice of Trustee Sale tacked to the garage door, you should notify the lender IN WRITING that you are a tenant living at the property. Give the lender your contact information. In some cases this will be the first inkling that the landlord doesn't live there, as some landlords got loans for properties by claiming that they were going to live at the property.
However, if you've notified the lender that you are a tenant living at the property, and given the lender your contact information, it will also notice more unscrupulous lenders that they cannot simply "evict" your former landlord from the property. And that's a good thing, because the first notice that you would receive would be the notice of eviction from the local Sheriff, giving you only a few days to move. (Unfortunately, should that happen, you need a real lawyer, and fast.)
Legally what should happen is that you should receive written notice that the property has been "sold"--either back to the lender or to a new owner. You would then know where to send the rent and who is responsible for repairs, maintenance and the like. This doesn't always happen though. Sometimes people aren't contacted for months after the foreclosure sale. In other cases the agent for the owner shows up and threatens tenants with immediate eviction.
So what do I do?
Know your rights, first of all. Second if the lender doesn't show up for months, don't spend the rent money on a vacation. The lender has the right to collect the rent, and may ask for it. This is particularly important in rent-controlled properties, or in communities with foreclosure eviction moratoriums, as the unscrupulous lenders have been known to try to evict protected tenants with a 3-days' notice to pay rent or quit. In some cases they did it after informing the tenants that they didn't have to pay rent. (As always, if you make an agreement with the lender's representative, get it IN WRITING. And yes, I am going to keep putting "in writing" in upper case letters because it is so important.)
Now with the passage of AB 1953, this will be more difficult for lenders or new owners, as new owners who don't give tenants their contact information within 15 days of the ownership change won't be able to evict tenants for nonpayment of rent. They can sue tenants, but can't evict them. However, it's not a good idea to spend the rent money, no matter how tempting that might be.
It's very likely that, however, you will receive a personal visit from the lender's representative, usually a realtor. (The realtor is chosen for a couple of reasons. First he is probably the person who will handle the sale of the building. Second he is not bound by the legal constraints that, say, a lawyer is, and can lie to you with impunity. A lawyer who tried to trick you out of your rights could be disbarred.)
And then, and then?
Let's go through the possibilities.