Yes, transit in the Bay Area is ridiculous...something like 26 separate transit systems. Driving from Union Square to Apple would probably be a little under an hour if you avoid rush hour...considerably longer during rush hour. (Also note that the Bay Area is very decentralized and so rush hour delays are often in the opposite direction you might think they'd be in.)
As for Caltrain: From Union Square, you'll have to take a bus (probably 30 or 45) to the Caltrain station at 4th and King Sts. That's a good ten minutes. (Note that the Caltrain station is near almost nothing except the baseball stadium...there are plans to extend the line under the city to a more central location...give us a decade or two.) Then you take Caltrain to Sunnyvale. Plan ahead to take the right train...not all trains stop at Sunnyvale. The run takes about an hour and 15 minutes...check the Caltrain site for timetables. Then you have to get to the Apple campus. Santa Clara County's bus system (the
VTA) should get you there, but now that I think about it, I think Apple and Sun co-sponsor a free shuttle to the tech campuses in that area during the morning and afternoon commute times. Technically, you may have to be an employee to use the shuttle, but as I recall, no one ever asks for ID. On-demand cabs from Sunnyvale are not likely, but I could be wrong about that.