You need to sign in to do that
Don't have an account?
Devendra Hirulkar 3
How to run a trigger for specific record types
Hello friends
i have created an trigger that copy one obj to another
but i have three record type like recordtype1, recordtype2, recordtype3 when i selected recordtype3 only the case the trigger have been fire otherwise it will not fire
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();
}
}
}
}
i have created an trigger that copy one obj to another
but i have three record type like recordtype1, recordtype2, recordtype3 when i selected recordtype3 only the case the trigger have been fire otherwise it will not fire
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();
}
}
}
}
All Answers
--Akram
just one change needed that is
NEW (Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('recordtype3').getRecordTypeId();)
OLD(Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'recordtype3'].Id;)