On 24th April 2012, There was Apex code chat conducted by the Salesforce. So i thought to share important question and answers of that chat. You can read complete chat here.
Here are some of the (edited) highlights from this episode’s chat transcript.
Question: Is there a way in Apex to send an email and replace the default from email address (email@example.com)?
Ans: Yes, using either the setSenderDisplayName or setOrgWideEmailAddressID methods on the SingleEmailMessage or MassEmailMessage classes.
Question: 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?
Ans: 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.).
Question: Does Apex support JavaDoc style documentation?
Ans: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.
Question: Is there any advantage to having just one “master” trigger per object, or should we have separate triggers for each functional requirement?
Ans: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.
Question: How can I return random records in a SOQL query (e.g for testing purposes)?
Ans: 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.
Question: Can we use Facebook credentials to log into a Customer Portal?
Ans:Yes – using the new Authentication Providers feature in Spring ’12. For more details, check out this webinar recording.
Question: Can we integrate Google Calender with the Salesforce Calender?
Ans:You can use this Google Data toolkit to implement a custom integration between Google Calendar and Salesforce.