function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sai ManojSai Manoj 

Merge existing two before insert triggers.

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: {
        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:{
    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);

         c.Accountid = AccMap.get(c.Account_Number__c).id;
         List<Contact> ConList = [select id, name from Contact where accountid =:c.accountid];
         c.Contactid = ConList[0].id;

Thanks in advance.