+ Start a Discussion
kumar.fdc81.3902978579608325E12kumar.fdc81.3902978579608325E12 

Apex class Issue displaying records in a list

Hi

When i select on gold i need to display different data.
As per my code i am getting last data only adding 5times.
i need different data in 5times.

public class TemplateTaskData {
public TemplateTaskData(ApexPages.StandardController controller) {
      lookupDataPop = new Template_Tasks__c ();
       //lookupDataPop = (Template_Tasks__c )controller.getrecord();
}
public Template_Tasks__c lookupDataPop{get;set;}
public string lkpdata {get;set;}
public  List<Template_Tasks__c> templatetask {get;set;}
 
    public pagereference currentData(){
    system.debug('lookupDataPop.Template__c****'+lookupDataPop .Template__c);
   templatetask = new list<Template_Tasks__c>();
if(lkpdata =='Gold')
{
lookupDataPop .Template__c = lookupDataPop .Template__c;
lookupDataPop.Task_name__c= 'Maestro 5 LMS Implementation Package';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 82;
} else if(lkpdata =='Bronze')
{

lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
} else if(lkpdata =='Silver')
{

lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
}
templatetask.add(lookupDataPop);

if(lkpdata =='Gold')
{
lookupDataPop .Template__c = lookupDataPop .Template__c;
lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 82;
} else if(lkpdata =='Bronze')
{

lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
} else if(lkpdata =='Silver')
{

lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
}
templatetask.add(lookupDataPop);

if(lkpdata =='Gold')
{
lookupDataPop .Template__c = lookupDataPop .Template__c;
lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 82;
} else if(lkpdata =='Bronze')
{

lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
} else if(lkpdata =='Silver')
{

lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
}
templatetask.add(lookupDataPop);
if(lkpdata =='Gold')
{
lookupDataPop .Template__c = lookupDataPop .Template__c;
lookupDataPop.Task_name__c= 'Data Migration - Full';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 82;
} else if(lkpdata =='Bronze')
{

lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
} else if(lkpdata =='Silver')
{

lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
}
templatetask.add(lookupDataPop);
if(lkpdata =='Gold')
{
lookupDataPop .Template__c = lookupDataPop .Template__c;
lookupDataPop.Task_name__c= 'Maestro Full data migration X3';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 82;
} else if(lkpdata =='Bronze')
{

lookupDataPop.Task_name__c= 'Data Migration';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
} else if(lkpdata =='Silver')
{

lookupDataPop.Task_name__c= 'Data migration - Express';
lookupDataPop.Billing_function__c = 'CN';
lookupDataPop.Billing_HOURS__c= 44;
}
templatetask.add(lookupDataPop);
   return null;
   }
}
ra1ra1
Hi Kumar,

Not sure if I can help you completely but below are my observation:

You are refering "lookupDataPop" at multiple places without reinitializing it. In every of your "if(lkpdata =='XXXX')" condition you are updating lookupDataPop field values and you are adding same reference variable in List and Salesforce was keeping reference-pointer of this variable not actual value.

Could you please try with below updated code ( I have updated only for "GOLD" condition), here I just initialize "lookupDataPop" before setting any value to its fields.


public pagereference currentData(){
  system.debug('lookupDataPop.Template__c****'+lookupDataPop .Template__c);
        templatetask = new list<Template_Tasks__c>();
        if(lkpdata =='Gold')
        {
        lookupDataPop = new Template_Tasks__c();
        lookupDataPop .Template__c = lookupDataPop .Template__c;
        lookupDataPop.Task_name__c= 'Maestro 5 LMS Implementation Package';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 82;
        } else if(lkpdata =='Bronze')
        {
       
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        } else if(lkpdata =='Silver')
        {
       
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        }
        templatetask.add(lookupDataPop);
       
        if(lkpdata =='Gold')
        {
  lookupDataPop = new Template_Tasks__c();
        lookupDataPop .Template__c = lookupDataPop .Template__c;
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 82;
        } else if(lkpdata =='Bronze')
        {
       
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        } else if(lkpdata =='Silver')
        {
       
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        }
        templatetask.add(lookupDataPop);
       
        if(lkpdata =='Gold')
        {
  lookupDataPop = new Template_Tasks__c();
        lookupDataPop .Template__c = lookupDataPop .Template__c;
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 82;
        } else if(lkpdata =='Bronze')
        {
       
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        } else if(lkpdata =='Silver')
        {
       
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        }
        templatetask.add(lookupDataPop);
        if(lkpdata =='Gold')
        {
            lookupDataPop = new Template_Tasks__c();
        lookupDataPop .Template__c = lookupDataPop .Template__c;
        lookupDataPop.Task_name__c= 'Data Migration - Full';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 82;
        } else if(lkpdata =='Bronze')
        {
       
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        } else if(lkpdata =='Silver')
        {
       
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        }
        templatetask.add(lookupDataPop);
        if(lkpdata =='Gold')
        {
            lookupDataPop = new Template_Tasks__c();
        lookupDataPop .Template__c = lookupDataPop .Template__c;
        lookupDataPop.Task_name__c= 'Maestro Full data migration X3';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 82;
        } else if(lkpdata =='Bronze')
        {
       
        lookupDataPop.Task_name__c= 'Data Migration';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        } else if(lkpdata =='Silver')
        {
       
        lookupDataPop.Task_name__c= 'Data migration - Express';
        lookupDataPop.Billing_function__c = 'CN';
        lookupDataPop.Billing_HOURS__c= 44;
        }
        templatetask.add(lookupDataPop);
           return null;
   }