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.
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.