+ Start a Discussion
RajaMohanRajaMohan 

How to map the list and Id

 Hi Folks,

 

How to map a ld with the list and display the same in the VF page??

 

For Eg:

Map<id,List<object__c>> obj=new Map<id,List<object__c>>();

 

Now, I want the fields in the object__c to be displayed in the VF page and want to update the same field via VF page.

 

Any examples will be helpful..

 

Thanks

Raj

Best Answer chosen by Admin (Salesforce Developers) 
RajaMohanRajaMohan

All Answers

Imran MohammedImran Mohammed

Can you be little more clear in what you want to get done?

 

To my understanding as of now, you should make use of Wrapper classes.

RajaMohanRajaMohan

Hi Imran,

 

Thanks for your reply.

 

I am having 3 custom objects naming Project__c, Project_Resource__c and Project_Resource__Allocation__c. The Project is having the master relationship with Project Resource. The Project Resource is the master of Project Resource Allocation. 

 

Now I am trying to map the Project Resource with the Project Resource Allocation from the master record Project.

 

I am mapping like Map<Id,List<Project_Resource__C>>. 

 

I need to display the values of the Project Resource Allocation in the VF page for the different Project Record name. How to do this?? If I want to use the wrapper classes then give me an example of using that.

 

Thanks for your valuable contribution.

 

Thanks

Raj

RajaMohanRajaMohan
This was selected as the best answer
SMasterSMaster
Hi Imran, I need your help regarding an issue that is related to send an email with selected attachment from the visualforce page...... i have a visualforce page that displayes Attachment of a custom object.... i have also used the inputcheckbox along with each record to select the attachment.... the need is to click the checkbox to select which file the user want to send as an attachment in the mail....... and then click send button..... I have tried implementing this using the wrapper class.... but unable to do so... please suggest
SMasterSMaster

 

I am getting the following error while saving the apex class:

 

Error: Compile Error: Loop variable must be an SObject or list of Attachment

 

please suggest...

 

I am using the following code:

 

public class Checkbox_Class 
{


        public class Attachmentwrapper
        {
            public Attachment acc{get; set;}
            public Boolean selected {get; set;}
            public Attachmentwrapper(Attachment a)
            {
                acc = a;
               selected = false;
            }
        }

        public Id oppr     {    get;set;    }         
        public Checkbox_Class(ApexPages.StandardController ctrl)    
        {       
        oppr = ctrl.getRecord().Id;         
        }
       
       
        List<Attachmentwrapper> AttachmentList = new List<Attachmentwrapper>();
        List<Attachment> selectedAttachments = new List<Attachment>();
       
        public List<Attachmentwrapper> getAttachments()
        {
        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
        {      
            AttachmentList.add(new Attachmentwrapper(a));
            return AttachmentList;
                               
        }
        }
         
        public PageReference getSelected()
        {
           
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         String[] toAddresses = new String[]{'SMaster@gmail.com'};
         mail.setToAddresses(toAddresses);
         mail.setReplyTo('SMaster@gmail.com');
         mail.setSenderDisplayName('CRM Support');
         mail.setBccSender(false);
         mail.setUseSignature(false);
         mail.setTargetObjectId('005Q0000000FR7f');
         mail.setTemplateId('00XQ0000000QULj');
         mail.saveAsActivity = false;
                          
         //selectedAttachments.clear();
         for(Attachmentwrapper accwrapper : AttachmentList)
         {
         if(accwrapper.selected == true)
         {
         List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
        {
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        fileAttachments.add(efa);
        }
        mail.setFileAttachments(fileAttachments);

        
        
         selectedAttachments.add(accwrapper.acc);
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
         return null;

         }
                  }       
       /* public List<Attachment> GetSelectedAttachments()
        {
            if(selectedAttachments.size()>0)
            return selectedAttachments;
            else
            return null;
        }  */  
       
            }
}