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
Jeannine2017Jeannine2017 

Issue with class and Visualforce page

I am trying to pull the AccountID from Healthcloud, and display it on a visualforce page and receiving visualforce error :  List index out of bounds: 0 
An unexpected error has occurred. Your development organization has been notified.

Here is my class:

public with sharing class PatientAccountController {
    
    public String accountId{get;set;}
    public String accountrelatedlist{get;set;}
    
    public PatientAccountController(){
        String cId = apexpages.currentPage().getParameters().get('recId');
        accountrelatedlist = apexpages.currentPage().getParameters().get('relatedlist');
        List<Contact> accID = [Select id, AccountId From Contact where Id = :cid Limit 10];
        accountId = accId[0].AccountId;
    }
}

Here is my visualforce page:

<apex:page controller="PatientAccountController" > docType="html-5.0" showHeader="false sidebar="false" applyHtmlTag="false" applyBodyTag="false" standardStylesheets="true"
    <html>
        <head>
            <meta charset="utf-8"/>
            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
          <style>
            html,
            body{
              height:100%;
              width:100%;
              background:#FFFFFF;
              font-family:ProximaNovaRegular, Arial, sans-serif;
              </style>    
                  
        </head>
        <body>
            <iframe id="Ifrmaccountlistview" src="/apex/DE_All_EMR_Data?id={!accountId}" width="100%" height="640px" scrolling="true" frameborder="false"></iframe>
        </body>
             
    </html>
</apex:page>


I have verified that there are active accounts in the org, Healthcloud is enabled, can someone explain why I am getting the error?
Best Answer chosen by Jeannine2017
Devanshu soodDevanshu sood
public with sharing class PatientAccountController {
    
    public String accountId{get;set;}
    public String accountrelatedlist{get;set;}
    
    public PatientAccountController(){
        String cId = apexpages.currentPage().getParameters().get('Id');
        accountrelatedlist = apexpages.currentPage().getParameters().get('relatedlist');
        List<Contact> accID = [Select id, AccountId From Contact where Id = :cid Limit 10];
        accountId = accId[0].AccountId;
    }
}

replace your class with this class and let me know if it doesnt work.

Devanshu

 

All Answers

Devanshu soodDevanshu sood
public with sharing class PatientAccountController {
    
    public String accountId{get;set;}
    public String accountrelatedlist{get;set;}
    
    public PatientAccountController(){
        String cId = apexpages.currentPage().getParameters().get('Id');
        accountrelatedlist = apexpages.currentPage().getParameters().get('relatedlist');
        List<Contact> accID = [Select id, AccountId From Contact where Id = :cid Limit 10];
        accountId = accId[0].AccountId;
    }
}

replace your class with this class and let me know if it doesnt work.

Devanshu

 

This was selected as the best answer
Devanshu soodDevanshu sood
Mark it as best awnser if it works
Mukesh_SfdcDevMukesh_SfdcDev
Hi Jeannine,

Your code is working fine.
Have you placed the contact record id in the visual force page URL ?
Like this : 
https://c.ap2.visual.force.com/apex/PatientController?recId=0012800000l1Ptx

Regards,
Mukesh

 
Jeannine2017Jeannine2017
Still receiving the same error message:
List index out of bounds: 0 
An unexpected error has occurred. Your development organization has been notified.
Devanshu soodDevanshu sood

User-added image

It is working in my org..just ensure that you passing ID to url like mukesh said 

https://c.ap2.visual.force.com/apex/PatientController?Id=0042800000l1Pdfx

 

Jeannine2017Jeannine2017
Ok, added the contact ID to the url and now receiving the User-added imagefollowing error:
Thank you for the help!
 
Jeannine2017Jeannine2017
Got it, thank you again for the help!
 
Mukesh_SfdcDevMukesh_SfdcDev
Hi Jeannine,

Thanks for your confirmation.

Keep learning!!!

Thanks,
​Mukesh