Validation rule in apex trigger

Salesforce provides validation rules in configuration for standard and custom objects. sometimes the requirements may not be fulfilled using validation rule, especially when the validation criteria is very complex or need querying in database to check previously created data. In such a case we can write validation logic in trigger.

In this article, I will demonstrate how to write validation logic in apex trigger.

Here in below example, there is before insert and before update trigger on Opportunity object. In this trigger the amount field has validated, for less than 5000.

trigger TriggerOpportunity on Opportunity (before insert, before update){
        if(opp.Amount < 5000){
            opp.Amount.adderror('Amount cannot be less than 5000.');


What is cloud computing?

Cloud Computing is the use of hardware and software to deliver a service over a network (typically the Internet). With cloud computing, users can access files and use applications from any device that can access the Internet.

There are 3 services that are fundamentally used in cloud computing:

  • Infrastructure as a service (IAAS)
  • Platform as a service (PAAS)
  • Software as a service (SAAS)

If you have a web based mail account hosted by Gmail, Yahoo, Hotmail, Rediffmail etc, then you have already experienced cloud computing. Instead of storing the mails on your computer It store them some where else, you use a browser to connect to the Internet and access the mails. The software and storage for your account doesn’t exist in your computer. This is one of the cloud computing service. You as an user simply access the services in cloud with your computer browser. But, in the back end there are various computers, servers and data storing systems that create the whole cloud computing system.
Infrastructure as a service (IAAS) :
In Infrastructure as a service (IAAS) the provider manages and delivers the underlying infrastructure, including storage, network and computing resources which can be used by software developers for building business solutions. Cloud users can install their operating system and their applications on the cloud infrastructure. Example of the companies that provide IAAS are Amazon EC2, Google compute engine, HP cloud etc.
Platform as a service (PAAS):
Platform as a service (PaaS) is a category of cloud computing services that provides a computing platform on top of which you can build a application as desired. The platform can include operating system, programming language, frameworks, libraries, services database and and other services that are required to host your developed application. Service provider could offer a developer tool which can be used to build services or database services or data storage services on the provided platform. Example of PAAS service providers are, Heroku, Azure cloud services, Google app engine.
Software as a service (SAAS):
Software as a service (SAAS) is a way of delivering applications over the Internet—as a service. Instead of installing and maintaining software, you simply access it via the Internet, freeing yourself from complex software and hardware management. An example of application service is CRM or ERP. SAAS delivers single application through the browser to number of customers using a multitenant architecture environment. is a Best known example of SAAS, that provides CRM application built on Other examples of SAAS are google apps, microsoft office 365.

Salesforce Enterprise WSDL Error in .Net – Unable to generate a temporary class (result=1)

“Unable to generate a temporary class (result=1)” is returned when .Net integration tries to parse the Enterprise WSDL version 32.0
In Winter ’15 (API version 32.0), a number of additional sObjects are available including ListViewRecord, whose definition is as follows:

<complextype name="ListViewRecord">
        <element maxoccurs="unbounded" name="columns" type="tns:ListViewRecordColumn"></element>

Here is the solution:

Change above xml to below format:

<complextype name="ListViewRecord">
        <element maxoccurs="unbounded" name="columns" type="tns:ListViewRecordColumn"></element>
<xsd:attribute name="tmp" type="xsd:string"></xsd:attribute>

As a result .Net integration fail due to a bug in .NET’s XmlSerializer as described in the following links:


Custom Clone Button in Salesforce

Salesforce provides Clone functionality for some standard objects(Standard Clone button), However some standard objects do not have this button. For this purpose of cloning we will need to create custom button that will perform the functionality of cloning.

This cloning functionality can be achieved by writing a javascript for this custom button.

As an example lets create a custom button “Clone” on Account object that will clone the record.

Simply override your custom button “Clone” with the following javascript and you will have your custom Clone button that functions exactly like standard clone button


Note: retUrl specifies the location where you want to be on press of back button.

Attachments in Salesforce

Salesforce attachment represents a file that a User has uploaded and attached to a parent standard or custom object record. The permission to attach an attachment to the parent object is depend on parent object permission.

Attachment Supported following Calls:

  • create()
  • delete()
  • describeSObjects()
  • getDeleted()
  • getUpdated()
  • query()
  • retrieve()
  • search()
  • undelete()
  • update()
  • upsert()

Notes and Attachments are available for Standard Controller by default. If it is not there you can adding it in a Page Layout related list and for custom object you have to enable Add Notes and Attachments related list to default page layout as shown below.

This above option will be only available when custom object is first created. If you wish to add/remove Notes and Attachment later you can add/remove it to related list at any time by using page layout.

Attachment Field:

Field Name Data Type Description
Body base64 Required. Encoded file data.
BodyLength integer Size of the file (in bytes).
ConnectionReceivedId reference ID of the PartnerNetworkConnection that shared this record with your organization. This field is only available if you have enabled Salesforce to Salesforce.
ConnectionSentId reference ID of the PartnerNetworkConnection that you shared this record with. This field is only available if you have enabled Salesforce to Salesforce.
ContentType string The content type of the attachment.

If the Don’t allow HTML uploads as attachments or document recordssecurity setting is enabled for your organization, you cannot upload files with the following file extensions: .htm, .html, .htt, .htx, .mhtm, .mhtml,.shtm, .shtml, .acgi, .svg.

Description textarea Description of the attachment. This field is available in API version 18.0 and later.
IsEncrypted boolean Indicates whether the attachment is encrypted using Platform Encryption(true) or not (false).
IsPartnerShared boolean Indicates whether this record is shared with a connection usingSalesforce to Salesforce. Label is Is Shared With Partner.
IsPrivate boolean Indicates whether this record is viewable only by the owner and administrators (true) or viewable by all otherwise-allowed users (false).
Name string Required. Name of the attached file. Label is File Name.
OwnerId reference ID of the User who owns the attachment.
ParentId reference Required. ID of the parent object of the attachment.

Access to fields depends on the method being used:

  • All of the fields are accessible using the describeSObjects() and query() calls. With thecreate() call, you can insert the Name, ParentId, Body, IsPrivate, and OwnerId fields.
  • To modify existing records, the update() call gives you access to change the Name, Body, IsPrivate and OwnerId fields.
  • You can access all of the fields using a query() call. However, you can’t receive the Body field for multiple records in a single query() call. If your query returns the Body field, your client application must ensure that only one row with one Attachment is returned; otherwise, an error occurs. A more effective approach is to return IDs (but not Attachment records in theBody field) from a query() call and then pass them into retrieve() calls that return the Bodyfield.

Limitation of Attachments :

  • Attachment maximum size that can be upload is 25 MB.
  • For a file attached to a Solution, the limit is 1.5 MB.
  • The maximum email attachment size is 3 MB.
  • The size limit for multiple files attached to the same email is 25 MB, with a maximum size of 5 MB per file.
  • The query call does not return attachments parented by email, unless the user performing the query has the “Modify All Data” permission.
  • Attachment records are not searched during text searches.
  • When issued by an administrator, the query results include Attachment records from the Recycle Bin.
  • When issued by a non-administrator, the queryAll() call results do not include Attachment records from the Recycle Bin.
  • You can create trigger for Attachment only by using developer console or Force IDE. Form Setup you can’t able to create a trigger for attachment.
  • By Using global $Action you can only able to download a file.For Attachment $Action will not support for Create(New) / Update(Edit) / View.
  • You can’t able to customize Notes and Attachment related list.If you want then go with Visual page replacing with standard Notes and Attachment related list.
  • You can’t able to create custom fields for Notes and Attachments.
  • Export attachments using Data Loader will give you file body as binary encrypted format.So you will face some problem while import it back.But you can use to import and export Salesforce attachment.