+ Start a Discussion
Devendra Hirulkar 3Devendra Hirulkar 3 

trigger that run only when perticular record type will be selected

Hello friends
i have created an trigger that  copy one obj to another 
but before copy it has three record type like recordtype1, recordtype2, recordtype3  when i selected recordtype3 only the case it can run 
so what i needed to do this

following is my trigger

trigger copypro  on Subsc__c  (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
  set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Product__c     != null)
    {
       cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
     }
  }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        
        for(Subsc__c s : trigger.new)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product_Name__c =pro;
                update Acc.values();
            }
        }
    }
   
}

   
Balaji BondarBalaji Bondar
Hi Devendra,

User below query to fetch the Id of Recordtype:
RecordType  recordtypeObj = [select Id, Name, Description, DeveloperName, IsActive from RecordType
where sobjecttype='Subsc__c' and Name = 'recordtype3' LIMIT 1];
Compaire recordtypeObj.Id with the record type of records which you want to process in trigger.

Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.