• Vethanbu Libertin
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Write trigger that country (custom field) field of account object  should get copied with the value of country(custom field) of contact object whenever a contact is created or account is updated

 
Hello, 
I'm trying to create a trigger to update a field based on the value of another field. The field I'm trying to update is a picklist and the values I'm trying to update it to are active picklist values. There are various HS_Original_Source__c values that if they are populated, I want the standard leadsource field to have it's equivilant value. Ex. HS_Original_Source__c is ORGANIC SEARCH and would map to leadsource of Organic Search.
 
trigger LeadSourceTrigger on Opportunity (before update, before insert) {
 List<Opportunity> oppList = new List<Opportunity>();
    
    //Go through the updated records coming into the database and update their custom fields 
    //according to the updated lead source 
    for(Opportunity opp : Trigger.new)
    {
        if(opp.LeadSource == '' && opp.HS_Original_Source__c != '' && opp.HS_Original_Source__c != 'OFFLINE')
        {
          if(opp.HS_Original_Source__c == 'ORGANIC SEARCH')
          {
               opp.LeadSource = 'Organic Search';
               System.debug('organic search');
           }
           /*
              if(opp.HS_Original_Source__c == 'next value')
          {
               opp.LeadSource = 'next value';
               System.debug('next value');
           }
           
           
            */
          
          //Put each updated record in the list created
          oppList.add(opp);  
        }
        
 }
 }

Any help would be much appreciated.