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
SimrinSimrin 

adding list to list

public List<ProfileSkillUser> searchResult{get;set;} 

function(){
public List<ProfileSkillUser> temp;
for (5 times){
	temp = [SELECT User.FirstName, User.LastName, ProfileSkill.Name, EFX_Type__C, ProfileSkill.EFX_Category__c, EFX_Skill_assessment__c
                        FROM ProfileSkillUser];

}

}


temp will populate value 5 times
searchResult should be addition/summation of temp
Best Answer chosen by Simrin
JayantJayant
What are you trying to do ? The code above is incorrect.

You can add list elements from one list to another by simply calling the addAll() method.

eg. List<Account> accounts1 = new List<Account>{a,b,c};
List<Account> accounts2 = new List<Account>{d,e,f};
accounts1.addAll(accounts2); //this will add all elements from list accounts2 to the list accounts1.

All Answers

PratikPratik (Salesforce Developers) 
Hi Simrin,

Will you please elaborate on your requirement so we can help.

Thanks,
Pratik
Patcs_1Patcs_1
Hi Simrin

As salesforce is having some governor limits, we should not query inside the for loop. 
 
public List<ProfileSkillUser> searchResult{get;set;}

function (){

public List<ProfileSkillUser> temp;
temp = [SELECT User.FirstName, User.LastName, ProfileSkill.Name, EFX_Type__C, ProfileSkill.EFX_Category__c, EFX_Skill_assessment__c   FROM ProfileSkillUser];

for (5 times){  
searchResult.add(temp);
 
}

}

Hope this helps.

P.S - Please mark this as solution by selecting it as best answer if this solves your problem.

Thanks
JayantJayant
What are you trying to do ? The code above is incorrect.

You can add list elements from one list to another by simply calling the addAll() method.

eg. List<Account> accounts1 = new List<Account>{a,b,c};
List<Account> accounts2 = new List<Account>{d,e,f};
accounts1.addAll(accounts2); //this will add all elements from list accounts2 to the list accounts1.
This was selected as the best answer
SimrinSimrin
code by Jayant, satisfies my use case.

I can also, use DML inside for loop