The function of the ileum is mainly to absorb vitamin B12 and bile salts and whatever products of digestion were not absorbed by the jejunum.