0

We have Trigger on Custom object(Appointment). We have different record types for that object and we don't want the functionality to one of it. Hence i am trying to add if condition inside the trigger comparing RecordTypeID.( if(appointmentsReference.RecordTypeId!='012b0000000M8ry')) It is throwing error. Variable doesn't exist

trigger AppointmentTrigger on Appointment__c (before insert, before update, after delete, after insert, after update) {


    if(Trigger.isBefore){
        if(Trigger.IsInsert){            


            new ConfidentialityManagement(Trigger.new,null).assignOnInsert('Account__c','Master_Account__c');
        }else if(trigger.isUpdate){
            new ConfidentialityManagement(Trigger.newMap,Trigger.oldMap).assignOnUpdate('Account__c','Master_Account__c');
        }

    } 

    else if (Trigger.isAfter) {

        Appointments appointmentsReference = new Appointments(Trigger.newMap, Trigger.oldMap);
        else if (Trigger.isAfter) {

            Appointments appointmentsReference = new Appointments(Trigger.newMap, Trigger.oldMap);
            if(appointmentsReference.RecordTypeId!='012b0000000M8ry')
            {
                if (Trigger.isInsert) {
                    AccountAssetsTeamManager.assignAssetTeamMembers(Trigger.new); /*  CD 7 | 10/6/2013 || Changed to generalize code | 24/3/2015 */
                    appointmentsReference.insertEvents(); /* CD 2 | Ewa Byra (ewa.byra@outbox.pl) | 4/6/2013 */
                } else if (Trigger.isUpdate) {
                    AccountAssetsTeamManager.changeAssetShares(Trigger.oldMap, Trigger.newMap); /*  CD 7 | 10/6/2013 || Changed to generalize code | 24/3/2015 */
                    appointmentsReference.updateEvents(); /* CD 2 | Ewa Byra (ewa.byra@outbox.pl) | 4/6/2013 */
                } else if (Trigger.isDelete) {
                    appointmentsReference.deleteEvents(); /* CD 2 | Ewa Byra (ewa.byra@outbox.pl) | 4/6/2013 */
                }
            }
        }
    }
}
  • Seems like your Appointments class is not having a RecordTypeId attribute. You need to ask a specific record for its record type Id. Or expose it via your wrapper class. – Basti Nov 2 '17 at 14:38
  • Which line is throwing the error? What variable doesn't exist? Even if you resolve that error you declare Appointments appointmentsReference twice (and also else if (trigger.isAfter)...) – Adrian Larson Nov 2 '17 at 14:39
  • In this line if(appointmentsReference .RecordTypeId!='012b0000000M8ry') Where i am trying to compare RecordType Id which i am excluding to run this logic. – User 7864 Nov 2 '17 at 14:41
  • -@Basti It has I can even query the name RecordType id by using query editor – User 7864 Nov 2 '17 at 14:43
  • If Appointment is a custom object shouldn't you need to append __c? – JaredT Nov 2 '17 at 14:43
2

Declare a Variable first for a Record Type.

id Recordtype =Schema.SObjectType.Appointment__c.getRecordTypeInfosByName().get('Your Record type Name').getRecordTypeId();

and then in If condition.

if(appointmentsReference.RecordTypeid!=Recordtype)
 {
    // enter your code
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.