• Sai Manoj
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi Experts,

Please find below two triggers, i need a help for merge these two triggers.

First Trigger:

trigger Case_SupportFirstSave on Case (before insert) {

    String strDefaultCaseProjectName = 'Support';
    String strDefaultCaseProjectID;
    String strRequestedUserID;

    for (Case objCase: Trigger.new) {
    
        If ((objCase.RecordTypeID == '012w00000006VBu') || (objCase.RecordTypeID == '012w00000006VBv')) {

            //Try to locate user record for person who logged the case
            list<User> objUsers = [select id, name from user where name = :objCase.SuppliedName and isActive = true limit 1];
            
            if (!objUsers.isEmpty()) { 
                objCase.Requested_By__c = objUsers[0].ID;
            }
            
            //If no project entered in by user; use support as default
            if (objCase.Project__c == null) { 
            
                //Locate Default Support Project by Name
                objCase.Project__c = [select id, name from SFDC_project__c where name = :strDefaultCaseProjectName limit 1].ID;
                
            }
                        
        }

    }
  

}


Second Trigger:

trigger AccountandContactUpdateTrigger on Case(before insert, before update){

    List<String> AccNoSet = new List<String>();
    
    for(Case c: trigger.new){
     AccNoSet.add(c.Account_Number__c);
    }
    
    Map<String, Account> AccMap  = new Map<String, Account>();

    for(Account acc : [SELECT Id, Parent_VRP_Number__c, VRP_Account_Number__c from Account where VRP_Account_Number__c IN :AccNoSet]){
     AccMap.put(acc.Parent_VRP_Number__c , acc);
    }
    

    
    for(Case c:trigger.new){
         c.Accountid = AccMap.get(c.Account_Number__c).id;
         
         if(c.accountid!=null){
         
         List<Contact> ConList = [select id, name from Contact where accountid =:c.accountid];
         
         if(!ConList.isempty()){
         c.Contactid = ConList[0].id;
         }
         }
    }
}

Thanks in advance.

Regards,
Sai
Hi Experts,
 
Please help me test class for below trigger.

​ 
Trigger AccountandContactUpdateTrigger on Case(before insert, before update){
 
    List<String> AccNoSet = new List<String>();
    for(Case c: trigger.new){
     AccNoSet.add(c.Account_Number__c);
    }
 
    Map<String, Account> AccMap  = new Map<String, Account>();
    for(Account acc : [SELECT Id, Parent_VRP_Number__c, VRP_Account_Number__c from Account where VRP_Account_Number__c IN :AccNoSet]){
     AccMap.put(acc.Parent_VRP_Number__c , acc);
    }
 
    for(Case c:trigger.new){
         c.Accountid = AccMap.get(c.Account_Number__c).id;
         if(c.accountid!=null){
         List<Contact> ConList = [select id, name from Contact where accountid =:c.accountid];
         if(!ConList.isempty()){
         c.Contactid = ConList[0].id;
         }
         }
    }
}
 
Regards,
Sai
Hi Experts,

I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.

User-added image

Regards,
Manu
Hi Experts,

I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.

User-added image

Regards,
Manu