• Tony Montana
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Account a = new Account(name = 'Microtek Inc');
insert a;
List<Contact> ContactList = new List<Contact>();
for (Integer i = 0; i < 5; i++) {
       contactList.add(new Contact
            (
            accountID = a.id;
            FirstName = 'Charles ' + i;
            LastName = 'Test Contact' + i;
            NT_Login_Name__c = 'testuser' + i;
            Management_Level_Type__c = 'Director';
            Former_Employee__c = false;
    ));

List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(contactList));
insert objects;

will above work ?
public class BEO_Send_Compliance_Survey_Class {
   
    @InvocableMethod
    public static void createParticipantRecord(List<Id> varRequestId)
    {
         Id SurveyRecipientRecordTypeId = Schema.SObjectType.Participant__c.getRecordTypeInfosByName().get('Survey Recipient').getRecordTypeId();
         Map<Id, Participant__c> createParticipants = new Map<Id,  Participant__c>();

         List<Contact> theContacts =[select id, name from contact where NT_Login_Name__c != null and Former_Employee__c = false and Management_Level_Type__c in ('VP','Director')];

        //FOR loop to run through Contact records in  theContacts

    for(Contact c : theContacts){
        createParticipants.put(c.Id, new Participant__c(Participant__c = c.Id, Request__c = varRequestId[0],RecordTypeId=SurveyRecipientRecordTypeId));
    }

    //Insert the values (individuals) in the createTheseIndividuals map

    insert createParticipants.values();
        
        
        system.debug('hi i m here');
    }
   
    
    
    
}

What should be the corresponding class with at least 80% coverage. ?

Thanks,
TM
if(requestId != null) {
        
               List<GLOBAL_Request__c> requestObj = [select id, business_unit__c, recordtype.developername from GLOBAL_Request__c where id=:requestId AND recordtype.developername = 'Send_Survey' Limit 1];
            if (requestObj != null){        
            List<User> usrRec =[select id, NT_Login_Name__c from User where id=:UserInfo.getUserId() And NT_Login_Name__c != null Limit 1];
                    if(usrRec != null){
                    List<Contact> contactRec = [select id, contactRec.NT_Login_Name__c from contact where NT_Login_Name__c=:usrRec.NT_Login_Name__c ORDER by LastModifiedDate DESC Limit 1];         
                        if (contactRec != null){
                          List<Participant__c> participantRec = [select Id, Name,Survey_Taken_Date__c from Participant__c where Participant__c=:contactRec.Id AND Request__c=:requestObj.Id ORDER by CreatedDate DESC LIMIT 1];
                            if(participantRec != null && participantRec.Survey_Taken_Date__c == null){
                                ParticipantId = participantRec.Id;
                                contactId = contactRec.Id;
                                requestId = requestObj.Id;
                                Participant__c updateSurveyTakenDate = new Participant__c(id = ParticipantId, Survey_Taken_Date__c = System.now());            
                                       upsert updateSurveyTakenDate;  
                            } else if(participantRec != null && participantRec.Survey_Taken_Date__c != null){
                                Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.LABS_SF_You_have_already_taken_this_survey));
                                return false;
                            } else {
                                Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.LABS_SF_Participant_Not_Part_Of_This_Pool));                    
                                 return false;
                            }
                        }
                    }
            }
        }
  
And I am getting the following error.


1.Variable does not exist: NT_Login_Name__c
2.Variable does not exist: Id
3.Variable does not exist: Survey_Taken_Date__c
4.Variable does not exist: Id
5.Variable does not exist: Survey_Taken_Date__c

Will appreciate your help.

Thanks,
TM
      
Account a = new Account(name = 'Microtek Inc');
insert a;
List<Contact> ContactList = new List<Contact>();
for (Integer i = 0; i < 5; i++) {
       contactList.add(new Contact
            (
            accountID = a.id;
            FirstName = 'Charles ' + i;
            LastName = 'Test Contact' + i;
            NT_Login_Name__c = 'testuser' + i;
            Management_Level_Type__c = 'Director';
            Former_Employee__c = false;
    ));

List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(contactList));
insert objects;

will above work ?