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
BeatofHeartBeatofHeart 

test class help

Dear Experts,

 

can you help me to write  a test class for the below class. Thanks in Advance. 

trigger UpdateVisitedCheckbox on Visit_Request__c (after insert, after update)
{
 
   
              List<Id> visitReqIds = new List<Id>();
              map< id, contact > contacts = new map< id, contact >();
             Id rtId = [SELECT Id FROM RecordType WHERE Name = 'Student' and SObjectType ='Contact' LIMIT 1].Id;
             Id rtId2 = [SELECT Id FROM RecordType WHERE Name = 'Student (PS)' and SObjectType ='contact' LIMIT 1].Id;
             '+rtid2);

           
          for(Visit_Request__c record:trigger.new)     
            {
                   
                   
                   if(record.Attendance_Status__c == 'Attended' )
                           
                                    
                                 {   
                                  
                                  visitReqIds.add(record.Contact__c);
                                    // contacts.put(record.contact__c, new contact(id=record.contact__c, Visited__c = TRUE));     
                                  }
                           

             }
             List<Contact> contactList = [Select Id, Visited__c, Name From Contact Where Id IN :visitReqIds AND RecordTypeId=:rtId ];
              System.debug('######'+contactList);
              for (Contact c : contactList)
                {
                  c.Visited__c = True;
                }
             update contactList;
                                     
             

 Beat

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Hi Beat,

 

Below is the sample example of test class for your Apex trigger.

 

Test Class:

@istest(seeAlldata = true)
public class TestUpdateVisitedCheckbox{
    Private Static testmethod void TestUpdateVisitedCheckbox(){
        Contact objcon = new contact();
	objcon.LastName = 'Test Contact';
	insert objcon;

	Visit_Request__c objVR = new Visit_Request__c();
	objVR.Attendance_Status__c = 'Attended';
	Contact__c = objcon.id;
	insert objVR;
    }
}

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

All Answers

hitesh90hitesh90

Hi Beat,

 

Below is the sample example of test class for your Apex trigger.

 

Test Class:

@istest(seeAlldata = true)
public class TestUpdateVisitedCheckbox{
    Private Static testmethod void TestUpdateVisitedCheckbox(){
        Contact objcon = new contact();
	objcon.LastName = 'Test Contact';
	insert objcon;

	Visit_Request__c objVR = new Visit_Request__c();
	objVR.Attendance_Status__c = 'Attended';
	Contact__c = objcon.id;
	insert objVR;
    }
}

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

This was selected as the best answer
BeatofHeartBeatofHeart

Thank you ..

Bikash.bhusalBikash.bhusal

  public string getAuthLink() {
                List<mpSettings__c> mps = mpSettings__c.getall().values();
                return mps[0].Ion_Portal_Base_Url__c.replace('http://','https://') + 'auth';
        }
        
        public PageReference auth_sites() {
                system.debug('\n####\n auth_sites \n####\n');
                // Get Custom Settings
                List<mpSettings__c> mps = mpSettings__c.getall().values();
                system.debug('\n####\n mps : ' + mps + '\n####\n');
                
                if(!mps.isEmpty()) {
                        String startUrl = '/'+ apexpages.currentPage().getparameters().get('retUrl');
                        system.debug('\n####\n startUrl : ' + startUrl + '\n####\n');
                        return Site.login(mps[0].Mobile_Portal_PRM_Username__c, mps[0].Mobile_Portal_PRM_Password__c, startUrl);
                        
                        
                //return pr;
                } else {
                        return null;
                }
                return null;
        }