Monday, April 8, 2013

Validations/Triggers/Functions


Validations/Triggers/Functions :

 Here is some examples to write Validations, Triggers and Functions on the custom fields of an object.   

Validations :

You can add validations both on Field and Object Level.

How to create Validation on Object :

   i am creating validation rule on an object where due date should not be more than 7 days.

 1. Click on new button on the Object rules section .
 2. Give the Rule name as "Due Date Validation" 
 3. Click on the Fields menu in the Rule definition area .
 4. Select Creation date field and click on  insert button,like below.

5.After insert you , you have write the due date condition and the error message to display when  
due date is more than 7 days like below.

6. Save and close . you validation rule is setup now. in the same way you can create for field level rules also.

Triggers :
Trigger fires on specific events, when a events occurs , the code in the trigger is executed.
we can create triggers by using CRM application composer.

How to create Trigger:
  Create a trigger, it should trigger when the user trying to create Ticket on the closed once. 

 1. Click on new button on the Trigger tab .
 2. Select After Create from List box of Tigger.
 3.Give the Trigger name as "Not to Open SR" 
 4. Click on the Detach button in the Trigger definition area .
 5.Click on the Fields menu and select the status and click on  insert button,like below.


6. After insert you , you have write the condition to to fire trigger and the error message like below .  

7. Save and close,your trigger is ready now.


Functions: 
      1.Object Functions  2. Global functions
Object Functions :

    1. These functions are useful for code that encapsulates business logic specific given object.  
    2.  You can call these functions by name from any other script related to the same Object.
          
How to create  Object  Functions:     
       Ex: calculate length of the Description Field.
    1. Click on new button on the Object Functions .
    2. Give the Function  name as "StrLength "
    3 .Click on the Detach button in the Function Body area .
    4.Click on the Functions  menu --> Category--> Text --length
 
5. Now you can add your field in the function like  "length(Description)"

Global Functions :

   1. These functions are useful for code that multiple objects wants to share. 
   2. To call a global function ,preface the function name with the adf.util.prefix.

  How to create  Global Functions:
   1. Move to Common Setup area and click on Global Functions.

  2. And follow the above steps which you used to create Object functions.

No comments:

Post a Comment