CodeTalk: Episode 001 - Apex

In this inaugural episode of CodeTalk, Sandeep, Quinton and special Guest Josh Kaplan (Senior Product Manager responsible for Apex) took audience questions on all things Apex. To learn more about the CodeTalk program, please go to the program website.

//www.youtube.com/watch?v=m64cGXeuXfc&feature=youtu.be

 

CodeTalk Chat Transcript

Here are some of the (edited) highlights from this episode’s chat transcript.

Q: Is there a way in Apex to send an email and replace the default from email address ([email protected])?
A: Yes, using either the setSenderDisplayName or setOrgWideEmailAddressID methods on the SingleEmailMessage or MassEmailMessage classes.

Q: Which fields are accessible in a Trigger.new record without performing a SOQL query? For example if my trigger is on the Contact object, are fields on the parent Account object (like Account Description) accessible without performing an explicit SOQL query?
A: You can use Trigger.new to access all non-null fields of the object on which the trigger is defined. You have to perform an explicit SOQL query to access any fields on associated parent or child records. For example, if the trigger is defined on Contact, you can only access the Id of the parent Account record (via AccountId) in Trigger.new. You’d need to perform a separate SOQL query to access any other field on the parent Acccount record (e.g. Description, Industry etc.).

Q: Does Apex support JavaDoc style documentation?
A: Apex does not natively support generating JavaDoc style documentation. However, the Force.com developer community has created an open-source tool to support this. More details can be found here.

Q: Is there any advantage to having just one “master” trigger per object, or should we have separate triggers for each functional requirement?
A: There is no hard or fast rule in the one vs many triggers per object debate. A lot depends on the specific use case and how you prefer to organize your code. Having a single ‘master’ trigger per object can help enforce order of code execution. Having all code in a single trigger can also be an appealing way to organize code. However, having separate triggers enforce different business requirements may increase code maintainability for some.

Q: How can I return random records in a SOQL query (e.g for testing purposes)?
A: The easy option would be to perform a SOQL query without a WITH or ORDER BY clause. A more advanced option would be to use a combination of SOQL OFFSET and Math.random() as described in this Stackoverflow thread.

Q: Can we use Facebook credentials to log into a Customer Portal?
A: Yes – using the new Authentication Providers feature in Spring ’12. For more details, check out this webinar recording.

Q: Can we integrate Google Calender with the Salesforce Calender?
A: You can use this Google Data toolkit to implement a custom integration between Google Calendar and Salesforce.

You can read the full chat transcript here.
tagged , Bookmark the permalink. Trackbacks are closed, but you can post a comment.
  • http://twitter.com/cirruscg Ryan Huff

    Great discussion. Sorry I missed it.
    Regarding the question about multiple triggers: we follow a strict practice of one trigger per object, per event. Meaning, we’ll have a “before” Account trigger and an “after” Account trigger. And our naming conventions are *set*: AccountBefore and AccountAfter. Occasionally when there’s a requirement that the same code needs to run before AND after, we’ll put it into one: AccountBeforeAfter. If you have overlap between triggers, you’ll never be able to control the order they fire in.

    Also, a shameless plug: We’re building Google/Salesforce Calendar sync: http://www.cirrusinsight.com. Check us out :)

    • Anonymous

      These are great best practices Ryan. Thanks for sharing with the community!