Yahaira Burgos was fearing the worst when her husband, Juan Vivares, reported to the Immigration and Customs Enforcement office in lower Manhattan in March. Vivares, who fled Colombia and entered the U.S. illegally in 2011, had recently been given a deportation order. Rather than hide, he showed up at the ICE office with Burgos and his lawyer to continue to press his case for asylum.

Vivares, 29, was detained for deportation. That’s when Burgos’ union sprang into action.

Prepared for Vivares’ detention, members of the Service Employees International Union Local 32BJ gathered for a rally outside the ICE office that afternoon, demanding his release. Union leadership appealed to New York’s congressional delegation, enlisting Senate Minority Leader Chuck Schumer (D) to reach out to ICE leadership. The union president even disseminated the name and phone number for the ICE officer handling Vivares’ deportation and urged allies to call him directly.

“I was very lucky to have a union,” said Burgos, a 39-year-old native of the Dominican Republic who works as a doorwoman on the Upper East Side. “They moved very fast. They moved every politician and every union member. ... If it were not for the union he would be deported.”

Vivares is now at home with Burgos and their 19-month-old son, having been granted a stay of deportation as the court considers his motion to reopen his asylum case. Although he’s far from being in the clear, his lawyer, Rebecca Press, says the union’s quick response was critical to keeping Vivares in the U.S. for now. “I do believe that their being able to reach the upper echelons of Congress gave us a window of time,” she said.

Vivares’ case provides a vivid example of the gritty work unions are doing to protect immigrant members and their families vulnerable to deportation in the Trump era.

Their efforts show the ways in which many unions ― particularly those in the low-wage service sector ― have become de facto immigrants rights groups advocating for their members. They also show how much organized labor on the whole has evolved on immigration issues. It wasn’t so long ago that unions generally viewed undocumented workers as competitors who undercut wages (in fairness, some unions still see them that way).

In recent months unions around the country have been hosting “know your rights” workshops to teach workers how to handle encounters with ICE agents and where to turn when someone is detained. They’ve provided legal assistance to and rallied around members and their families who have wound up in deportation proceedings. And they have made a concerted push to win language in union contracts aimed at avoiding deportations and helping workers who run into problems with their immigration papers.

“We’re trying to make people realize that part of the power of being organized at work is you really do have the ability to get additional binding protections if you have the strength to win them at the bargaining table,” said Shannon Lederer, the director of immigration policy at the AFL-CIO, a federation of 56 unions.

Some unions have gotten employers to agree to notify a shop steward whenever ICE or the Department of Homeland Security reaches out to the company about employees’ status. They have also succeeded in getting companies to agree not to allow immigration officials onto the worksite unless they have a warrant. In some contracts, employers have vowed not to conduct “self audits” of their employees’ immigration paperwork unless the feds force them to.

While these tactics predated Trump’s election, unions are now making them a priority. The AFL-CIO recently distributed a nearly 200-page toolkit to its member unions that included contract language they could push for with respect to immigration. In many cases, companies and unions have a mutual self-interest in enacting the protections: Employers do not want to lose trained workers, and unions do not want their members deported.

Ron Herrera, the secretary-treasurer at Teamsters Local 396 in Los Angeles, said it was a point of pride for his union to secure clauses in their sanitation contracts guaranteeing workers a grace period for dealing with any snags that come up with their work papers. The contract assures that, so long as they can eventually clear up the problem, the workers won’t lose their jobs or their seniority while they deal with immigration officials.

Herrera said he has received two phone calls in the past week from alarmed members who are working under the Deferred Action for Childhood Arrivals program, which was created by President Barack Obama. The program granted legal work status to an estimated 800,000 young undocumented immigrants who’d come to the U.S. as children. Last week Trump said he would rescind DACA in six months, leaving it to Congress to pass legislation authorizing such a program.

Herrera’s union is a good example of the changing demographics of many labor groups. As a Latino, Herrera said, he was an affirmative action hire at UPS in the 1970s. Now, many of the workplaces his union represents are predominantly Latino. “Even if somebody has legal residence, a lot of times there’s a family member that doesn’t,” he said. “We need to step up and understand that this social issue is actually a work issue, too.”

One of the most powerful things a union can do for an undocumented worker or family member is intervene politically on his or her behalf. Not all cases turn out like that of Juan Vivares. Eber Garcia Vasquez, a Long Island sanitation worker and father of three U.S.-born children, was detained by ICE last month. He had left Guatemala and entered the U.S. illegally 27 years ago. His union, Teamsters Local 813, rallied in lower Manhatta after he was detained, and the union’s Washington lobbyists took his case directly to the Trump administration.

Garcia Vasquez was nonetheless sent back to Guatemala last week, according to the Daily News. He hadn’t been back since he left more than a quarter-century ago.

Many unions have launched training programs aimed at helping members navigate run-ins with immigration agents. In Seattle, an immigrant rights group taught members of SEIU Local 775 how to run such workshops; the union’s members in turn were able to fan out and teach colleagues.

“It’s stuff that we’ve always had on our radar but we kicked into high gear,” said Heather Villanueva, one of the union’s organizers. “The tone changed from generally talking about it to literally trying to protect families once Trump was elected.”

In Austin, Texas, the teachers union has been doling out Fifth Amendment rights cards and packets to help students’ families plan for immigration raids. Many teachers sought out rights training from the union after seeing how frightened their students’ families had become, according to Montserrat Garibay, the vice president of Education Austin. They have been partnering with pro bono immigration attorneys to host presentations for families after school hours.

“We feel this is a crisis that the Latino immigrant community is going through right now,” Garibay said. “As teachers we feel an ethical and moral responsibility.”

The hotel and hospitality union Unite Here, which is heavily immigrant, went so far as to create a ringtone in Spanish called “Nada Nada,” with lyrics enumerating one’s rights when la migra comes knocking: “If immigration comes to arrest you, keep calm / You have the right to not sign anything and not say anything.”

Maria Elena Durazo, Unite Here’s general vice president, said the union redoubled its efforts on immigrant rights once it saw Trump’s cabinet taking shape, with nominees such as Jeff Sessions, now attorney general, making clear that the deportation talk was more than campaign bluster. The union wants to insert more immigration safeguards into new contracts moving forward, like having employers contribute to assistance funds for undocumented workers who lose their jobs, she said.

Part of the challenge unions face, Durazo said, is making all their members see the value of such investments, particularly those who have little sympathy for undocumented immigrants.

“The main thing is to understand the union as an organization of their fellow workers, that we’re all in this together,” she said. “In some places, that could be more difficult: Why are we doing this if they’re here undocumented? It takes a lot of work to build that kind of clarity and solidarity.”