Buying stocks during a bear market can yield spectacular returns. For instance, the bear market brought on by the Great Recession cratered the S&P 500 by 56.8%, from peak to trough. But smart investors knew it was a once-in-a-lifetime opportunity to buy.

The index closed on March 9, 2009, at its bottom of 676.53. The ensuing bull market rally lifted the S&P 500 to its peak of 3,386 11 years later, on Feb. 19, 2020. Steadfast buy-and-hold investors would've achieved a remarkable 400.5% gain just by buying the index.

Buying an index is not a bad idea. Still, bear markets allow investors to buy beaten-down shares of great companies, outperform the market, and accumulate phenomenal wealth.

What if you bought Salesforce during the Great Recession instead?

On the day the S&P 500 bottomed, Salesforce (CRM 1.27%) closed at $7.72 per share. If you plunked down $1,000 at that price, you'd have 129 shares. If you had the fortitude to never sell a single share for the entire 11-year rally, your shares would've been vaulted to $192.87 per share, earning you a hefty 2,398% gain -- dramatically outperforming the market during that 11-year span.

A group of people holding a cloud icon.

Image source: Getty Images.

To put the Salesforce investment in an even longer-term perspective, your guts to buy in a bear market, loyalty to the buy-and-hold strategy, and your $1,000 would equate to $19,371.93 today.

Here's how Salesforce did it

Salesforce has long been a cloud-based software growth story. The company's incredibly popular customer relationship management (CRM) software has given its corporate users' sales teams the collaboration and marketing tools to strengthen customer relationships and expand their sales opportunities. In short, Salesforce helps its users increase revenue and become more efficient sales machines.

Over Salesforce's history, it has accumulated an impressive catalog of clients. As an ingrained part of each customer's business, Salesforce is in a perfect spot to sell them additional software and services. As such, the company has been busy acquiring companies with adjacent services and upselling them to its existing customers.

For example, it acquired ExactTarget in 2013, with just $286 million in revenue. Since then, Salesforce has grown its revenue by 949% to $3 billion. Salesforce later took over MuleSoft in 2018, when it had $284 million in revenue. The company grew its revenue by 499% to $1.7 billion.

Salesforce's latest (and largest) acquisitions offer what are perhaps its most significant opportunities. The company bought Tableau in 2019 and Slack Technologies in 2021. Revenue at those two companies has already grown, which may be the next chapter of Salesforce's growth story.

Is it too late to buy Salesforce?

When examining Salesforce's revenue history, it's easy to see that its products work. It finished its fiscal year as a publicly traded company in 2005 with $176 million in recurring software revenue. Seventeen years later, in fiscal 2021, the company had vaulted its revenue by 14,952% to $26.5 billion. The company's astonishing revenue growth has done wonders for the stock, but nowadays, investors want to see profits.

Salesforce's full fiscal year ending Jan. 31, 2022, included an adjusted operating margin of 18.7%. But during the company's annual investor conference this month, Salesforce's management shared some exciting news that seems to have fallen on deaf ears. Management forecasts that by 2026, the company will nearly double its revenue to over $50 billion, and its adjusted operating margin will soar to 25%.

Yet Salesforce stock is down since the announcement and has shed 41% this year. Wall Street analysts expect Salesforce to generate $4.74 in earnings per share for its current fiscal year. That number implies a forward price-to-earnings ratio (based on forecasts) of 31 times, which is considerably more attractive than its five-year average of 57 times. Given Salesforce's growth trajectory, the bear market is giving smart long-term investors a gift.

CRM PE Ratio (Forward) Chart

CRM PE Ratio (Forward) data by YCharts

Buy now or wait?

There is no telling when today's bear market will give way to the bulls. But the stock market is always forward looking. So, the risk of waiting for good macroeconomic news is missing out on the recovery. Buying the stocks of great companies at depressed prices is a recipe for market-beating returns. Even if it means the bear market persists for a while, it's better than suffering from the regret of missing out on opportunities like this.