Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

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){
    for(Opportunity opp:trigger.new){
        if(opp.Amount < 5000){
            opp.Amount.adderror('Amount cannot be less than 5000.');
        }
    }
}

download

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 Force.com, 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. Salesforce.com is a Best known example of SAAS, that provides CRM application built on force.com. 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">
    <sequence>
        <element maxoccurs="unbounded" name="columns" type="tns:ListViewRecordColumn"></element>
    </sequence>
</complextype>

Here is the solution:

Change above xml to below format:

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

As a result .Net integration fail due to a bug in .NET’s XmlSerializer as described in the following links: https://connect.microsoft.com/VisualStudio/feedback/details/471297

download

How to get the system MAC address using C#?

Media Access Control (MAC) address is a unique identifier assigned to most network adapters or network interface cards (NICs) by the manufacturer for identification and used in the Media Access Control protocol sub-layer. If assigned by the manufacturer, a MAC address usually encodes the manufacturer’s registered identification number. It also be known as an Ethernet Hardware Address (EHA).

In this article, I will demonstrate how to get system MAC address using C#.

public string GetMACAddress()
{
    var macAddress = string.Empty;
    NetworkInterface[] onjNI = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in onjNI)
    {
        if (string.IsNullOrEmpty(macAddress))
        {
           IPInterfaceProperties objIP = adapter.GetIPProperties();
           macAddress = adapter.GetPhysicalAddress().ToString();
 
           if(!string.IsNullOrEmpty(macAddress))
           {
               break;
           }
        }
    }
  return macAddress;
 }

How to set up Database Mail in SQL Server?

To send email using SQL Server, we need to setup Database mail. In this article, I will demonstrate how to set up SQL Server Database Mail.

Steps to Setup Database mail in SQL Server:
Step 1:
Expand “Management” folder and select “Database Mail”.

1

Step 2:
Right click on “Database Mail” and select “Configure Database Mail”.

2

Step 3:
After click on “Database Mail” you will get below screen, click on “Next” button.

3

Step 4:
Here select first option and click on “Next” button.

4

Step 5:
Here enter the “Profile Name” and “Description” and click on Add button to add SMTP account.

5

Step 6:
Enter “Account Name” and “Description”. In the Outgouing Mail Server(SMTP) section enter Email Address, Display Name, Reply E-Mail Address (If required), Server Name and Port Number. In SMTP authentication select “Basic Authentication” option enter User Name, Password and Confirm Password and then click on “Ok” button.

6

Step 7:
Click on “Next” button.

7

Step 8:
Click on “Next” button.

8

Step 9:
Click on “Finish” button.

9

Step 10:
Click on “Close” button.

10

Step 11:
After create the Account and the Profile successfully, we need to configure the Database Mail. To configure it, we need to enable the Database Mail XPs parameter through the sp_configure stored procedure, Below are the sample code:

sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO

11

Now I have completed all configuration for “Database Mail” setup and ready to send email. To send mail, we need to execute a stored procedure sp_send_dbmail and provide the required parameters. Below are sample code to send a test mail:

USE msdb
GO
EXEC sp_send_dbmail @profile_name='Test Profile',
@recipients='biswajeet@biswajeetsamal.com',
@subject='Test message',
@body='This is a test message.'

12

Also we can send test email from here.

Step 1:
Expand management folder and right click on “Database Email” and click on “Send Test E-Mail”.

13

Step 2:
Here select Database Mail profile, from which profile you want to send E-Mail, and enter to E-Mail address, subject, body and click on “Send Test E-Mail” button. And now check your To e-mail box.

14