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
Sapana WSapana W 

Inserting record with particular record type

trigger ENT_Trigger_insertNonQEIDisbursements on ENT_NMTC_Non_QLICI_Disbursement__c (after insert)
{
    //List<ENT_NMTC_QEI_Non_QEI_Disbursements__c> DisbList = new List<ENT_NMTC_QEI_Non_QEI_Disbursements__c>();
    
 
      
     
       
        if (Trigger.isInsert)
        {   
        
            //Id rtId = [select Id,name from RecordType where name='Non-QEI' and SObjectType='ENT_NMTC_QEI_Non_QEI_Disbursements__c' limit 1].id;
            for(ENT_NMTC_Non_QLICI_Disbursement__c NonDisb : trigger.new)
            {
                List<ENT_NMTC_QEI_Non_QEI_Disbursements__c> DisbListToInsert = new List<ENT_NMTC_QEI_Non_QEI_Disbursements__c>();
                ENT_NMTC_QEI_Non_QEI_Disbursements__c InsertDisb = new ENT_NMTC_QEI_Non_QEI_Disbursements__c(NMTC_Non_QLICI_Disbursement__c=NonDisb.Id,RecordType.name=Non_QEI);
                
                InsertDisb.Deal_Exit_Date__c = NonDisb.Deal_Exit_Date__c;
                //InsertDisb.RecordTypeId = rtId;              
                
                RecordType.Name = 'Non-QEI';
                InsertDisb.Deal_Originated_Date1__c = NonDisb.Deal_Originated_Date__c;
                InsertDisb.Disbursement_Date__c = NonDisb.Disbursement_Date__c;
                InsertDisb.Disbursement_ID__c = NonDisb.NMTC_NonQLICI_Disbursement_ID__c;
                InsertDisb.Disbursement_Source__c = NonDisb.NMTC_Non_QEI_Contribution__c;
                InsertDisb.Not_Yet_Disbursed_Projected_QEI__c = NonDisb.Not_Yet_Disbursed_Projected_QEI__c;
                InsertDisb.Originator_Transaction_ID__c = NonDisb.Product_Originator_Transaction_ID__c;
                InsertDisb.Source_Amount__c = NonDisb.Amount__c;
                InsertDisb.Total_Disbursement_Amount__c = NonDisb.Amount__c;
                DisbListToInsert.add(InsertDisb);  
        
                if(DisbListToInsert.size()>0)
                {
                    insert DisbListToInsert;
                }
            }
    }  
      
      
    
}

 

 

Everything else is working fine accept that I am not able to set a record type for newly inserted record. I have tried many ways and later commented them all. Please guide me through this

Best Answer chosen by Admin (Salesforce Developers) 
ItswasItswas
Hi Extensia,

You can use below code to insert a record for a particular record type.

RecordType objRecType = [SELECT Id,Name,SobjectType FROM RecordType where Name = 'Non-QEI' limit 1];(use this before using for loop)
InsertDisb.RecordTypeId = objRecType.Id ;(Assign it inside the for loop)

Please try from your end and let me know whether it worked or not.

Regards,
Itswas.

All Answers

ItswasItswas
Hi Extensia,

You can use below code to insert a record for a particular record type.

RecordType objRecType = [SELECT Id,Name,SobjectType FROM RecordType where Name = 'Non-QEI' limit 1];(use this before using for loop)
InsertDisb.RecordTypeId = objRecType.Id ;(Assign it inside the for loop)

Please try from your end and let me know whether it worked or not.

Regards,
Itswas.
This was selected as the best answer
Sapana WSapana W
Thanks, It worked!!!