Skip to main content
Renu Kulkarni 님이 #Data Management에 질문했습니다
I want to write a Trigger whenever a custom object "candidate" record is created or updated and the field " US Citizen" value is unchecked then other field " Visa Required" should be automatically checked(True).

 

I Can do this with workflow rule but want to try it writing a trigger.    Im very new to salesforce :-)
답변 4개
  1. 2013년 4월 24일 오후 7:04
    Welcome to the world of force.com

     

    Tip number 1 :

     

    When ever you can do something using Point and click (i.e. workflows, formulas etc..) , go for it and try to avoid coding.

     

    Reason being , code has more chances of failure , constraints of governor limits and also you have to write test classes for each trigger / class you write.

     

    To answer your question 

     

    Goto the Object --> on Trigger Section of the object detail --> click new

     

    might look like this

     

    difference between before and after trigger

     

    http://hisrinu.wordpress.com/2011/05/17/difference-between-before-trigger-and-after-trigger/

     

    Trigger mytriggerName on Candate__c (before update,before insert)

     

    {

     

      // Bulkify the code : i.e. expect more than 1 record to come in to trigger at same time 

     

       for(Candidate__c c: Trigger.new)

     

     {

     

       if(!c.US_Citizen__c)

     

          c.Visa_Required__c = true;

     

      // Since its before trigger you dont need to update the object that you triggerd

     

    }

     

    }
0/9000