Salesforce: Trigger on Attachment – Restricting user from attaching files with specific extensions

By default Salesforce don’t allow admin to configure or restrict user from adding specific type of files. Admin may need that user should not be able to attach files of type exe, dll which can have virus in them. Also there is no virus check is done when file is getting uploaded to the Salesforce.

But Salesforce does allow writing trigger on the Attachment Object by which you can implement such restrictions. Following is the snippet of the code which will restrict user from adding the files with extension mentioned in the set list. You can also edit the code and do the reverse by checking if extension exist in the set then only allow attaching the file.

trigger AttachmentTrigger on Attachment (before insert) {
set<String> setExtNotAllowed = new set<String> {‘exe’,’dll’};
for (Attachment attachment
String strFilename = attachment.Name.toLowerCase();
List<String> parts = strFilename.splitByCharacterType();
attachment.addError(‘File with extension exe or dll could not be attached!!’);

Once trigger code is up and running, whenever Salesforce tries to attach any file with extension exe or dll he will come across following error message.


Changing default RDP port of Amazon EC2 server

First thing you should do if you are hosting a server in AWS cloud is to change its default ports.

Why one should do that?

  1. Does changing default port number actually increase security?
  2. The 5 biggest security mistakes users make in Amazon’s cloud
  3. AWS Security Alert: Insecure RDP Server Configuration


1. Configure your Security Group and allow inbound access to the custom port you want to use for RDP (Say 7777). You can get more information about the Security Groups here.

Once done, next step is to open up the port 7777 from the server firewall so that external system can connect on this port.

You can manually open up the port from the Firewall settings or you can run following command if you have admin access.

netsh advfirewall firewall add rule name=Custom RDP Port dir=in action=allow protocol=TCP localport=7777

Last step is to change the RDP listening Port:

To change the port that Remote Desktop listens on, follow these steps.

Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:

322756 How to back up and restore the registry in Windows
  1. Start Registry Editor.
  2. Locate and then click the following registry subkey:
  3. On the Edit menu, click Modify, and then click Decimal.
  4. Type the new port number(7777 in our case), and then click OK.
  5. Quit Registry Editor.
  6. Restart the computer.

Creating multiple tabs for same Salesforce Object

Many time I have seen Salesforce Admins wants multiple tabs for same object depending upon the RecordTypes or some other criteria like separate tabs for Premium Account, Gold Accounts and Silver. Indeed they can create multiple views and use the picklist and use “Go” button. But it has disadvantage like multiple clicks, not that user friendly.

In short there is no direct way of creating multiple tabs for same object in Salesforce. Then I thought of creating an Apex component which will take some inputs like ObjectName, Fields to display and criteria/Filter. This appraoch was needing too much of coding and generic code writing for supporting it for all objects. And it was limited to the query filter one can have.

Creating multiple views is the feature inbuilt provided by the Salesforce and is very powerful. So I thought to use the apex:enhancedList control which takes the viewId as a parameter. You can find the documentation for the EnhancedList here. The most important thing is apex:enhancedlist only requires the viewid.

I created a simple VisualForce Page like below.

<apex:page >
<apex:enhancedList height=”600″ rowsPerPage=”25″ id=”AccountList” listid=”{!$CurrentPage.Parameters.viewId}” customizable=”false”/>

I wanted to reuse this page so I didn’t added any standard controller to the Page itself.

Then now comes the step of creating the Tabs. Sample purpose I am taking Account’s views.

Salesforce support following three types of tab creation:

  1. Custom Object Tabs: – Not suitable to above approach.
  2. VisualForce Tabs: – This will work but do not allow passing the parameters from the URL, so this will not allow reuse of the same page.
  3. Web Tabs: – This allows any URL integration into the tab and suits requirement.
Complex task is to find the viewId. I didnt found it straight forward.
Creating the Tab now:
Now add this tab to your SelectedTabs.

Salesforce: Adding specific working days to a Date

Many time while coding we come across the requirement in which we need to calculate the Enddate from a StartDate after specific number of business/working days. That means excluding the weekends (Saturday & Sunday) Following is the code snippet which does this. I know there can be optimize way for doing this. But I didn’t wanted to spend more time on this.

Below method takes date and number of working days to be added to the date.

global Datetime addBussinessDays(Datetime startDate, Integer iDays)
Datetime endDate = startDate.addDays(iDays);
Integer iOffDays = daysOff(startDate,endDate);
return endDate.addDays(iOffDays);

Method daysOff calculates the number of non-working days coming in the start date and end date. And after which we are again adding those number of days.

global Integer daysOff(Datetime sdate, Datetime edate)
Integer iCount = 0;
while (sdate < edate) {
if (sdate.format('E') == 'Sat' | sdate.format('E') == 'Sun'){
iCount = iCount + 1;
sdate = sdate.addDays(1);
return iCount;