Increasing Code Coverage to Include Catch Blocks [Salesforce]

In Salesforce, it can sometimes be frustrating driving your Apex Class & Trigger Code Coverage up to get beyond the 75%, 80%, or 85%+ marks.  Some of the more difficult parts of that process can be covering all scenarios to achieve this. In particular, this post focuses on code not executed within the try-catch constructs count against the overall Code Coverage calculations. With a simple refactor, we can remedy that without changing the underlying functionality of the core class — just the test class. The try-catch we will start with before our changes have the following format: try { // … Read More

How to Bypass Validation from Apex Across Objects [Salesforce]

If your Salesforce org has Triggers and Apex, you’ve probably run into the issue of hitting Validation Rules (VRs) when your Apex code tries to insert or update a record. The example below is across two objects and how you can solve for it. Let’s say you have an object called Positions and another object called Applicants. There is a lookup field on Applicants to the Position object. On the Positions object, you have a date field called Last Interview Date to identify the latest date an applicant was interviewed. Due to the relationship between Applicants and Positions only being … Read More

Migrating from Oracle Portal 10g to Oracle APEX

Migrating from Oracle Portal 10g to Oracle Application Express (APEX)

There are several enterprises that are currently running the Oracle 10g middleware platform for their front-end applications. They have Oracle Portal 10g or prior versions delivering content for their Oracle Forms, Oracle Reports, and Oracle Discoverer based applications, all running on Oracle Application Server (OAS) 10g. Many of these OAS 10g environments also run Oracle Internet Directory (OID) 10g and Oracle Single Sign-On (OSSO) 10g. Oracle provides a supported and easily repeatable upgrade path for Oracle Database 11g, however, the upgrade of components running on OAS 10g moving to Oracle WebLogic Server (WLS) 11g is not quite as straightforward. Oracle … Read More

Creating Tasks from Apex in Salesforce

Creating Tasks from Apex in Salesforce

Tasks in are a powerful tool that can help users and managers in the environment complete assignments associated to business processes. You can create tasks manually, through workflows, or custom Apex code. In this blog, we are going to show you how to create a task via Apex Code. When creating a new Task, you will need to include all required fields from the Task object. By default the Subject, OwnerId, Status, and WhatId fields are required, and will need to be included in the Task creation, along with any other fields your organization have marked as required. The … Read More

How to Create a Public RESTful Web Service on a Site

How to Create a Public RESTful Web Service on a Site

In the following tutorial we make a simple RESTful Web Service on a site. So lets get started, we will first create a Apex class by navigating to Your Name | Setup | Develop | Apex Classes | New Below is the  Apex code, @RestResource(urlMapping=’/myservice’) global class MyService { @HttpGet global static String doGet() { String name = RestContext.request.params.get(‘name’); return ‘Hello ‘+name; } } Now the next step is to make this Apex class accessible via Public URL. Navigate to Your Name | Setup | Develop | Sites   Click the name of the site you want to control. … Read More

Sending Emails from Apex

Sending Emails from Apex in Salesforce

Salesforce allows administrators to send emails based on workflow actions that are triggered within the environment. You can perform the same functionality utilizing Apex trigger code after you set your trigger logic. In this example we are going to send an email to an Account Owner once an Opportunity has been created for their Account. We will cover the following functionality: Querying the Account object for the Owner Querying for the required Email Template Establishing the email Sending the email   //list for emails List emails = new List(); //query email template object EmailTemplate et=[Select id from EmailTemplate where name=:’Hello … Read More

Storing Record IDs from a List View in Salesforce

Storing Record IDs from a List View in Salesforce

Built into Salesforce is the ability to add buttons onto List Views. This is an extremely helpful and powerful solution for updating records without needing to navigate onto the record detail page. In this blog post, I aim to cover how to implement selecting records to update, along with handling multiple record selections. Part 1: Storing and Passing IDs Salesforce provides built in syntax to capture the user selected record. In the button logic you will need to provide this piece of code: var oId= {!GETRECORDIDS($ObjectType.Object)}; This stores the user selected record Id into a variable which then can be … Read More Platform Fundamentals: SOQL and SOSL Platform Fundamentals: SOQL and SOSL

SOQL (Salesforce Object Query Language) Use SOQL to construct simple but powerful query strings in the queryString parameter in the query() call, in Apex statements, in Visualforce controllers and getter methods, or in the Schema Explorer of the IDE SOQL statements are similar to the select statement in SQL SOQL statements are case-sensitive SOQL statements can be used in Apex and the Web Services API If the output of a SOQL statement is an “Consider and Index Filter” error, it means the statement is returning too many records in which case you need to use a WHERE clause to restrict … Read More