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
AbAb 

Execute trigger for particular record type

Hello,

I have a trigger like below, how can i make it execute only for one record type.Name
trigger XTrigger on Order (after update) {
    if (Trigger.isAfter && Trigger.IsUpdate) {
        Class_Name.functionName(Trigger.new);
    }

Thank you for suggestion
Best Answer chosen by Ab
Raj VakatiRaj Vakati
try like this
 
trigger XTrigger on Order (after update) {
	
String name = [select Id,Name from RecordType where sObjectType='Order' and Name ='Your record type'].Name ; 

    if (Trigger.isAfter && Trigger.IsUpdate) {
		if(name =='Your record type'){
        Class_Name.functionName(Trigger.new);
		}
    }
	
}

 

All Answers

KrishnaAvvaKrishnaAvva
Hi Sandrine,

You can query the recordx type and use that in your if condition.
select Id,Name from RecordType where sObjectType='Account' and Name ="Your record type";

Update the if condition to check for the recordType.

Regards,
Krishna Avva
SarvaniSarvani
Hello Sandrine,

Try this code below
trigger  XTrigger on Order (after update)
{
    Id recordTypeId = [Select Id,name from recordType Where sObjectType = 'Order' AND Name = 'recordtypeName'].Id;
    List<Order> orderlist = new List<Order>();
	if (Trigger.isAfter && Trigger.IsUpdate) {
        for (Order O : Trigger.new){
             if(O.RecordTypeId == recordTypeId){
             orderList.add(s);
		      }
	    }
	if(orderList.size()>0)
	{
	//Do something
	}
	}
}
Hope this helps !

Thanks,
Sarvani
 
Raj VakatiRaj Vakati
try like this
 
trigger XTrigger on Order (after update) {
	
String name = [select Id,Name from RecordType where sObjectType='Order' and Name ='Your record type'].Name ; 

    if (Trigger.isAfter && Trigger.IsUpdate) {
		if(name =='Your record type'){
        Class_Name.functionName(Trigger.new);
		}
    }
	
}

 
This was selected as the best answer