0

Class

private List<Contact> RepCombinedAttachment;
Public List<CombinedAttachment> RepComAttachment;

public List<CombinedAttachment> getRepComAttachment() {
    return RepComAttachment;
} 
public CombinedAttachmentcont(ApexPages.StandardController controller) {

     ViewData();
 }
public void ViewData()
{
    RepCombinedAttachment = Database.query('Select (Select id, title, LastModifiedDate,
        createdby.name,RecordType From CombinedAttachments) from Contact where ID=:id');

    for (Contact c : RepCombinedAttachment)
    {
        for(CombinedAttachment temp : c.CombinedAttachments)
        {
            if(!temp.isEmpty())
            RepComAttachment.add(temp);
        }
    }
}

Error Message:

Compile Error: Method does not exist or incorrect signature: [CombinedAttachment].isEmpty()

Could someone please help me fix this issue.

3
for(CombinedAttachment temp : c.CombinedAttachments)
{
        //if(!temp.isEmpty())
        RepComAttachment.add(temp);
 }

isEmpty() is the list class method in order to check sobject. You may want to use any field is null or not

remove if(!temp.isEmpty())


Edit

in constructor

public CombinedAttachmentcont(ApexPages.StandardController controller) {
     RepCombinedAttachment = new List<Contact>();
     RepComAttachment = new  List<CombinedAttachment>();
     ViewData();
 }
| improve this answer | |
  • I removed it, but getting "Attempt to de-reference a null object " error. while executing visualforce page. – Dinesh Jan 5 '16 at 14:37
  • hey @Dinesh can you just point me in which you are getting error? It will be better if you add complete code – Ratan Paul Jan 5 '16 at 14:38
  • public List<CombinedAttachment> getRepComAttachment() {return RepComAttachment;} public CombinedAttachmentcont(ApexPages.StandardController controller) { ViewData(); } Below the viewdata(), I have just the above code. – Dinesh Jan 5 '16 at 14:46
  • VF Code: <apex:form > <apex:pageBlock title="Notes & Attachments" id="CApageBlock"> <apex:pageblocktable value="{!RepComAttachment}" var="a"> <apex:column value="{!a.RecordType}"/> </apex:pageblocktable> </apex:pageBlock> </apex:form> – Dinesh Jan 5 '16 at 14:49
  • 1
    There is lot to learn..Thank you so much for your help !!! – Dinesh Jan 5 '16 at 15:09
1

Modify your code in following way

for ( Contact c : RepCombinedAttachment)
{
      //Check for isEmpty first and then do the loop.
      if(!c.CombinedAttachments.isEmpty())
      {
        for(CombinedAttachment temp : c.CombinedAttachments)
        {
            RepComAttachment.add(temp);
        }
     }
   }

}
| improve this answer | |
1

As Ratan already explained, the following is the issue you are asking about:

for(CombinedAttachment temp : c.CombinedAttachments)
{
  //if(!temp.isEmpty())
  RepComAttachment.add(temp);
}

temp is an object variable, not a collection. There is no isEmpty on it.

Your second issue is that you aren't bringing back any records from your query. You have no variable called 'id', yet you are trying to query by it. You need to fix the following query:

RepCombinedAttachment = Database.query('Select (Select id, title, LastModifiedDate,
        createdby.name,RecordType From CombinedAttachments) from Contact where ID=:id');

EDIT:

Just look at Ratan's edit to his answer. It should now be correct.

| improve this answer | |
  • I have declared, id id = ApexPages.currentPage().getParameters().get('id');. still getting the same error. – Dinesh Jan 5 '16 at 14:52
  • @Dinesh Where is your error? Update your question please. – dphil Jan 5 '16 at 14:58
  • Just look at Ratan's edit to his answer. It should now be correct. – dphil Jan 5 '16 at 15:00

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.