Category Archives: Apex Tip

Tip: the simplest way to list all objects

Since SFDC contains variable objects (custom and standard) we have many times to list them.

This is a simple snippet to do it.

Tip Apex: get SObject Type from Id

This is a really piece of cake apex snippet. Extremely useful when you are developing generic methods.

About Martin Borthiry

I’m a fully trained and qualified software engineer with more than 15 years of varied experience, specialized in frontend performance, web developing , cloud computing, salesforce, as well as CRM functionalties and Social Networks. Specialties: Salesforce.com Platform & Web Performance Optimization. Salesforce.com Developer and Administrator Certified. Senior Frontend, Javascript and HTML5. Heavy Ajax WebApps Mobile WebApps – Phonegap Webapps Developer (Php/Django/Python) Team Work & Managment

Tip Apex: Select * from X on apex (SOQL)

I’ve faced many times two problems on SOQL queries:

1. They have not * (star) operator and hence it is really tough to list all fields on large objects.
2. If you try to modify a field name or delete or update the type, salesforce won’t allow you if it is referenced on the code. It is really painful on deploys.

As a best practices when I have to retrieve all fields I use this simple function.

About Martin Borthiry

I’m a fully trained and qualified software engineer with more than 15 years of varied experience, specialized in frontend performance, web developing , cloud computing, salesforce, as well as CRM functionalties and Social Networks. Specialties: Salesforce.com Platform & Web Performance Optimization. Salesforce.com Developer and Administrator Certified. Senior Frontend, Javascript and HTML5. Heavy Ajax WebApps Mobile WebApps – Phonegap Webapps Developer (Php/Django/Python) Team Work & Managment

Apex Tip: check if field exists on SObject

This small function check if any SObject contains a field, really useful on many cases.

For instance if you want to know if country Picklist is active, you could check countryCode field active.

Other approach using JSON serializer

Sample use:

About Martin Borthiry

I’m a fully trained and qualified software engineer with more than 15 years of varied experience, specialized in frontend performance, web developing , cloud computing, salesforce, as well as CRM functionalties and Social Networks. Specialties: Salesforce.com Platform & Web Performance Optimization. Salesforce.com Developer and Administrator Certified. Senior Frontend, Javascript and HTML5. Heavy Ajax WebApps Mobile WebApps – Phonegap Webapps Developer (Php/Django/Python) Team Work & Managment