You need to sign in to do that
Don't have an account?
Tony Montana 6
Hi , I have below block of code.
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
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
Instead of Null check use the IsEmpty function to check the list has data or not:
IsEmpty function will solve the List index out of bounds: 0 issue.
Thanks,
Maharajan.C
All Answers
while accessing the record from LIst please specify the array element number to access the data.
for ex: usrRec.NT_Login_Name__c. --> usrRec[0].NT_Login_Name__c
Please try the below code:
Thanks,
Maharajan.C
I'm sure it will help you.
don't forget to mark it as best answer.
Thank you
thanks for your help. It resolved the syntactical errors but i recieved another error during test.
Error:List index out of bounds: 0
What could be the cause?
Regards
TM
Instead of Null check use the IsEmpty function to check the list has data or not:
IsEmpty function will solve the List index out of bounds: 0 issue.
Thanks,
Maharajan.C
Best Regards,
TM
good luck have fun (https://fun888.co/)