You need to sign in to do that
Don't have an account?
Thomasm
Trigger Based on record type
I am looking to have my trigger used based on the record type of the custom object. So only use the trigger if recordtype = daily visit. Here is the trigger i am using. Any suggestions on how this could work
trigger SV_Cases on SiteVisit__c (before insert) {
List<Case>cases=new List<Case>();
for(sitevisit__C b:Trigger.new)
{
if(b.baseboard_stairway__c == 'False')
{
Case newCase=new Case(subject='Test',Status='New',Origin='Web');
insert newCase;
}
}
}
The above code will loop through your Sitevisit__c object, check if the Record Type is daily visit, and if so continue with the code. I moved the insert statement out of the for loop in order to bulkify it and avoid hitting governor limits (good practice).
I believe this should work. Have fun.
Hi
You can check record type Name Like this way
trigger SV_Cases on SiteVisit__c (before insert) {
List<Case>cases=new List<Case>();
for(SiteVisit__c sVisit : [Select Id, RecordTypeId, RecordType.Name From SiteVisit__c Where Id IN : Trigger.newMap]) {
if(sVisit.RecordType.Name == 'Test') {
//Your Logic here
}
}
Thanks
Hit the Kudos button (star) and Mark as solution if it post helps you
i am getting a compile error: Variable does not exist: sitevisit__C.REcordType
//To get Id
sitevisit__C.RecordTypeId
//To get name
sitevisit__C.RecordType.Name