"My friend gave me an apple."
Translation:Mia amiko donis al mi pomon.
Because "pomon" is the object of "donis" (which requires the accusative) but "mi" is the object of the prepositional phrase "al mi". Words after a preposition don't take the accusative case unless indicating movement, which would be redundant in this case since "al" already indicates movement.
"pomon" is accusative because it is the direct object of "donis"
"mi" is the object of the preposition "al"
In the English "My friend gave me an apple", "me" is dative because it is the indirect object. The apple is what was given, me is who it was given to.