If you're investing for the very long term (i.e., forever), then the good news is you don't need to worry about what's happening with the economy. Over the years, the economy has recovered from wars, recessions, and everything else in between. While many businesses have failed during that time, companies with solid fundamentals and quality products behind them are safe bets to stand the test of time.

A couple of potential stocks that you can confidently hold forever are AbbVie (ABBV -0.41%) and Coca-Cola (KO -0.46%). Not only are these moneymaking machines, but they also dish out a lot of cash to their shareholders through dividends. Year to date, they've both delivered positive gains and are doing better than the S&P 500.

1. AbbVie

What makes AbbVie a solid buy-and-hold investment is that the company is diverse, has excellent margins, and generates plenty of free cash flow. Those are solid pillars that can enable the business to continually grow over the years. 

The company's pipeline features projects that span many therapeutic areas, including oncology, immunology, neuroscience, aesthetics, and eye care. AbbVie has dozens of trials ongoing, many of which are in phase 3 and near the finish line. 

This year, it has several drugs that have already generated more than $1 billion in revenue, including immunology treatments Skyrizi and Rinvoq, two products that will pick up the slack from the inevitable decline in revenue from top-selling rheumatoid arthritis drug Humira, which loses exclusivity next year and has amassed nearly $16 billion in sales over the past three quarters. Investors are concerned about its patent cliff, but management is confident the duo of Skyrizi and Rinvoq could reach a higher combined peak.

The reality is that every successful healthcare company will have to worry about replacing its top-selling products at some point. Patents don't last forever, and long-term healthcare investors should instead prioritize investing in businesses like AbbVie with solid fundamentals that can either acquire a big business (like its mammoth $63 billion acquisition of Botox-maker Allergan in 2020) or afford to invest in research and development and work on strengthening its pipeline, which AbbVie has done.

With revenue of $57.8 billion and a strong profit of $13.3 billion over the trailing 12 months, AbbVie's strong fundamentals put it in a fantastic position to continue growing while withstanding adversity. It has also accumulated a free cash flow of $21.9 billion during the past four quarters. To further incentivize long-term investors, AbbVie also pays a dividend yield of 3.6% (better than the S&P 500 average of 1.7%) and is a Dividend King.

The stock currently trades at a multiple of 22 times earnings, which is in line with the healthcare average. AbbVie is an all-around solid investment to buy and hold for the rest of your life.

2. Coca-Cola

A top consumer goods company like Coca-Cola doesn't always have to reinvent new products as it can rely on the success of its top brands for decades, building off multiple variations of it. But the company has also diversified into healthier products so that it isn't overly dependent on just a few product lines. With hundreds of brands in its portfolio, Coca-Cola can serve many types of customers.

In its most recent earnings results (for the period ended Sept. 30), the company's sales rose by 10% from the prior-year period to $11.1 billion. While its trademark Coca-Cola products gained 3%, it was its Coca-Cola Zero Sugar brand that jumped by a more impressive 11%. Even its hydration, sports, and coffee and tea products generated more growth at 5%. The growth rates are encouraging and suggest that the diversification Coca-Cola has achieved over the years has made the business more resilient and a better buy in the long haul.

The company has generated a profit of $9.9 billion over the past four quarters on revenue of $42.3 billion, for an impressive profit margin of 23%. Free cash flow during that time has also been strong at over $10 billion. 

Like AbbVie, Coca-Cola is a Dividend King, and its yield is relatively high at 2.7%. At 28 times earnings, the stock is a bit expensive (the S&P 500 average is 20), but that could improve over the years as the economy recovers and with the business still finding ways to grow. For a top company such as Coca-Cola, it's easy for investors to justify a bit of a premium, given how solid its operations are.