Meta Platforms Inc. topped projections for second-quarter sales and gave a stronger-than-expected forecast for the current period, a sign that the social media company’s advertising business is still growing quickly enough to support aggressive spending on artificial intelligence.