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

By default, Salesforce doesn’t allow admin to configure or restrict a user from adding a specific type of files. Admin may need that user should not be able to attach files of type exe, dll which can have the virus in them. Also, there is no virus check is done when a 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 the 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 exists in the set then only allow attaching the file.

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.


Salesforce: Adding specific working days to a Date

UPDATE: If you want to consider holidays and business hours you can check out this article.

Many time while coding we come across the requirement in which we need to calculate the EndDate from a StartDate after a 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 an optimized way of doing this. But I didn’t want to spend more time on this.

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

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.


I was constantly getting exception when I tried to use the “/soap/ajax/15.0/connection.js” in the VF Page.
JavaScript throws following exception:-

Invalid SessionID

{faultcode:'sf:INVALID_SESSION_ID', faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session', detail:{UnexpectedErrorFault:{exceptionCode:'INVALID_SESSION_ID', exceptionMessage:'Invalid Session ID found in SessionHeader: Illegal Session', }, }, }

The exception was resolved when I added following statement before using the “sforce.connection” object in the JavaScript.

sforce.connection.sessionId = “{!$Api.Session_ID}


C# : Converting DateTime to format YYYY-MM-DDThh:mm:ssZ

I found that lots of people were searching to convert the datetime into the universal format. Following can be used for the same.



string strDate = DateTime.UtcNow.ToString(“yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss’Z'”, DateTimeFormatInfo.InvariantInfo);

The custom format string is “yyyy’-‘MM’-‘dd HH’:’mm’:’ss’Z'”.