Sunday, October 28, 2012

Can we set standard field to be unique? administrators and consultants often get business requirement to set standard fields to be unique. In some companies, we need to make sure every mobile phone in Contacts have to be unique (if it is not blank).

And as we known, until now, we are not able to set standard field be unique, only custom field have this option.

So, any solution? Yes, there are few ways to get this done, from a simple one until a difficult one.

1. Trigger

Using trigger may be not a simple way, we need a developer who well understand Salesforce Apex Trigger. Developer need to write apex code in Developer instance or Sandbox instance, make sure the test method coverage above 75% and deploy it to production. 

Developer may be like this approach, although it is not something prefer by administrator. Trigger in Contact before insert and before update, query all Contact with mobile phone enter, if query result is > 0, add error and don't allow to save or update that Contact.

2. Using new custom field

Instead of using standard standard field, using the same sample as above, we can build a new Mobile Phone field with field type = Phone. And hide standard Mobile Phone field from Field-Level Security (Prefer not just hide from Page Layout).

But, if this is an enhancement, it would be more effort to extract existing data to external file, verify there is no duplicate value and import the data back to the new fields. This even become worst, if the standard field has been used in many places, such as: reports, apex code, workflow, etc.

3. Workflow + Field Update

This is prefer option with less effort. Create a new custom field and enable Unique option then hide it from page layout. Create a workflow with criteria ISNEW() || ISCHANGED(MobilePhone). Create immediate workflow action to update the new field above. 

This option may be more simple, but the error message shown is not clear as it is not say what field is duplicate, but just inform it is duplicate with which record, example: "Duplicate value on record: John Wood". User do not know exactly what is duplicate between Contact working on with John Wood, if we have more than 1 field need to be set unique. 

Tuesday, October 23, 2012

Can we set Salesforce user password?

As Salesforce administrator, we often get question from our user, "can you check what is my password? " hmmmm, some users often think like some legacy applications, where system admin able to see or modify Salesforce password.

In Salesforce is different, it is so secure, system admin and everyone else not able to see or modify any user password. But, as the best practice, we offer to reset their password, and Salesforce will send email to the user with instruction to set new password by  their own, and it should works fine.

But again, some users (read: senior management) not really want to bother by checking email and so on, even the request is come from his/her secretary. So how? No problem, we can change user email to her secretary email, secretary confirm email change in her email (although Salesforce also will email to the original email say that the email has been changed to new one), and reset password. It works, yay!!! 

But, how to change back the user email to the original one? The senior management need to click a link again in her email (she may have hundreds or thousands email never read). Problem.

So, I just start think if there is an easy way to set user password without have to go through such complicated process? It is worst when the user is going to present something in 5 minutes and we do not have much time to do above process. So, can we set user password?

YES, it is possible, this function is not exist in Salesforce setup menu, but Salesforce is kind enough to provide system administrator with Developer Console. Yes, Developer Console is for developer as it named, but admin also can use it for other purpose, like set user password, yay!!!

How? It is easy, just few clicks, copy and paste a short code below will do. Navigate to your name and click Developer Console menu.  It will open new window, Debug | Open Execute Anonymous Window, copy and paste code below to the Enter Apex Code windows and click Execute button. System.setPassword('00550000000rlrX', 'hello123');

In this sample: 00550000000rlrX is the User Id, if you are Salesforce admin, you should now this Id well, and hello123 is the new password to set.

But, if you still too lazy to check the User Id manually, and you have the username, you can just copy and paste statement below into Apex code execute box:
System.setPassword([SELECT Id FROM User WHERE username=''].Id, 'hello123');

Below sample code to set password of all active user in one go:

List<User> userList = new List<User>();
userList = [SELECT Id from User WHERE IsActive = true];
for (User u : userList)
    System.setPassword(u.Id, 'hello123');
    System.debug('DONE: ' + u.Id);

You can modify the SOQL above as needed, example: only for profile = "Sales Rep".

All statements above is apex code, but we can utilize it for other productive work as needed. 

Sunday, October 21, 2012

Can we publish image from ?

Kita dapat mem-publish suatu image untuk di-share ke internet untuk dapat di akses secara public, dari menggunakan menggunakan Flickr atau Photobucket dan lain sebagai nya. Tetapi sebagai pengguna, apakah kita bisa mem-publish image yang ada di

Jawaban nya IYA, Anda bisa. Ada beberapa cara untuk sharing image yang ada di, dari yang simple sampai dengan yang rumit. Beberapa di antara nya:

Untuk meng-akses image dari suatu attachment yang tagged ke suatu object, dibutuhkan login ke instance yang dapat meng-akses attachment tersebut. Jadi attachment bukan merupakan option untuk kebutuhan ini.

Static Resource
Diperlukan Visualforce page untuk meng-akses image yang ada di Static Resource. Jadi kita harus membuat Visualforce page untuk mengakses image yang ada di Static Resource, dari menu Setup - App Setup - Develop - Pages dan click button New.

<apex:page showHeader="false">
<apex:image url="{!$Resource.Logo_SFDC}"/>

Perhatikan nama static resource yang digunakan di atas adalah Logo_SFDC. Dan pastikan Cache Control di set ke Public. Supaya Visualforce page yang di buat dapat di akses oleh public, kita perlu membuat Site baru (bila belum ada) atau masukkan Visualforce page tersebut ke Site yang sudah ada, contoh:

Jadi, menyimpan gambar pada static resource dapat di akses oleh public, tetapi ini bukan cara yang simple dan membutuhkan bantuan Site.

Anda dapat meng-upload gambar sebagai document di dari dropdown Create New... atau dari tab Document (tergantung dari konfigurasi Anda). Pastikan option Externally Available Image pada document yang mau di share diaktifkan. 

Image pada document dapat di akses langsung oleh public tanpa perlu login ke, misal nya:

Ganti nama instance (dalam hal ini penulis menggunakan "my domain" johanmilis2-developer-edition--c.ap1) dengan instance Anda, misal nya: na1, na2, na6, eu0, dll. Ganti nilai pada parameter id dengan Document Id yang mau di publish, biasanya di mulai dengan 015. Dan ganti nilai pada parameter oid dengan Organization Id Anda, biasanya di mulai dengan 00D. Anda dapat menggunakan image type JPG, GIF, PNG untuk kebutuhan ini. 

Jadi Document merupakan pilihan untuk share image yang di ada di ke public dengan simple.