0

When i create new User Account and login with that credentials, it gives me this problem if admin doesnt have set thier values yet !!!**

AllotmentList = [select id, Days_Remaining__c from PTO_Allotment__c where Year__c =:year and Employee__c=:EmployeeList[0].id LIMIT 100]; //access only Current user Allotment details
                //to handle Listoutof Bound Exception wrote if-else

        if(AllotmentList.size()>0)
        {
        requests.PTO_Allotment__c=AllotmentList[0].id;
        requests.Days_Remaining__c=AllotmentList[0].Days_Remaining__c;
        }
        else
        {
            //write a code when AllotmentList is empty ....

       }
  • I have tried isEmpty() also – Nilesh Apr 19 '14 at 6:48
1

Before you're querying with the employee id, you have to verify if it exists. For instance:

if(employeeList.isEmpty()){
        // continue your business logic in an alternative track
        AllotmentList = [SELECT id, Days_Remaining__c 
                         FROM PTO_Allotment__c 
                         WHERE Year__c =:year 
                         AND Employee__c=:EmployeeList[0].id LIMIT 100
                        ];

        // do some error messaging here maybe
}else{
        // process as expected
       AllotmentList = [SELECT id, Days_Remaining__c 
                        FROM PTO_Allotment__c 
                        WHERE Year__c =:year  LIMIT 100
                       ];
}
  • Thank you Sir, I am done with it, I was missing that only, Now I checked for the Emp record too first and it worked. – Nilesh Apr 19 '14 at 7:37

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.