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
Samadhan Sakhale 3Samadhan Sakhale 3 

Record Type In Trigger

Hello,
    I have write one trigger to copy one field to another but my problem is how can this trigger run only if RecordType="User Group"
My Trigger is

trigger copySubtoAcc on Subscription__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 (Subscription__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Membership_Type__c != null)
    {
       cObjectID.add(s.Membership_Type__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(Subscription__c s : trigger.new)
        {
             if(cObjectMap.get(s.Membership_Type__c).Name != Null)
            {
                 String pro= cObjectMap.get(s.Membership_Type__c).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product__c,(SELECT ID,Membership_Type__c  FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product__c =pro;
                update Acc.values();
            }
        }
    }
   
}


Thanks,
Sam
sharathchandra thukkanisharathchandra thukkani
For example If you are talking about subscription record type. then

for (Subscription__c s : [SELECT Id FROM Subscription__c WHERE  RecordType.Name = 'User Group']){



hope you got the answer..