public class SetChallenge1 { public void checking(List l1,List l2,List l3){ set s= new set(); s.addall(l2); s.retainAll(l1); s.retainAll(l3); System.debug('Common Elements' + s); } }
@Salesforce Hulk Hello Shrey, Hope you are doing well. I'm a beginner in salesforce and watching Apex programming videos and the 'MAP' collection is missing in the playlist. Could you please add MAP video to this playlist so we can complete the collection part? please add because your teaching way is very learnable for us and this missing since last 2 years Thanks
is sObject is generic type which will store all types of data right ?, then whey we are using interger, string data type for storing integer and string values ?...Please correct me if i wrong
Hi Shrey.. Could you please make a session on apex triggers.. It would be really really helpful. though there are no. of videos on triggers, i believe your explanation will be perfect, and makes one to understand it in a very clear way.
list l1 = new list {1,4,7,8}; list l2 = new list {2,5,3,6,4,8,9}; list l3 = new list {9,5,2,7,4}; set sn = new set (); sn.addall(l3); System.debug(sn.retainAll(l1)); system.debug(sn); //common b/w l3 and l1 System.debug(sn.retainAll(l2)); system.debug(sn); //common b/w l3 and l2 also l1 //Complexity :- O(1)
Hey Salesforce hulk i have q question, whenever i try to execute different commands which i have learned from you it keep giving me the error of " Method does not exist or incorrect signature" , then after that it has happened quite a lot now, where i try to add custom feild in account by __c , .ADDALL or .contians . i have tried everything even copying the code which you used in your example. DID'NT WORK!! please guide what is the real issue here?
Apex Class With commonElements() method public class SetCommonValues { public void commonElements(Set s1, Set s2, Set s3){ Set commonElements = new Set(); commonElements.addAll(s1); commonElements.addAll(s2); commonElements.addAll(s3); commonElements.retainAll(s1); commonElements.retainAll(s2); commonElements.retainAll(s3); System.debug('Common Elements : ' + commonElements); } } How to call from Anonymous Window SetCommonValues s = new SetCommonValues(); Set s1 = new Set{15,19,20,22,29,65,75}; Set s2 = new Set{19,22,24,26,45,65,70}; Set s3 = new Set{2,4,9,18,19,22,65,75}; s.commonElements(s1,s2,s3); Result : 22:56:09:004 USER_DEBUG [15]|DEBUG| Common Elements : {19, 22, 65}
public static void SetQuery(List lst1,List lst2, List lst3){ // To find the list of common elements in three Lists recieved as an argument // Ex 1) lst1 = {1,4,7,8} lst2={2,5,3,6,4,8,9} lst3={9,5,2,7,4} // Required Output to be List Comm = {4} List Comm = new List(); for (integer i = 0; i
public class Practices { public static Set unique(List l1, List l2, List l3){ Set s = new Set(); for (Integer i : l1){ if (l2.contains(i) && l3.contains(i)) s.add(i); } return s; } }
The method: public class Junior_hulk { public static Set commonInt(List l1,List l2,List l3) { set s=new set(); s.addall(l1); s.retainall(l2); s.retainall(l3); system.debug('ommon set of integers-->'+(s)); return s; } } Calling the method: list l1=new List{1,4,7,8}; list l2=new List{2,5,3,6,4,8,9}; list l3=new List{9,5,2,7,4}; set s_new=new set(); s_new=Junior_hulk.commonInt(l1,l2,l3); system.debug(s_new);
Ok. Here's my best shot at the 1st example: List l1 = New List {1,4,7,8}; List l2 = New List {2,5,3,6,4,8,9}; List l3 = New List {1,4,7,8}; Set s2= new Set (); s2.addall (l1); s2.addall (l2); s2.addall (l3); System.debug(s2.Contains(4)); Can you tell me if this is right or give me a hint if it's wrong? I think I need to use ContainsAll but I was having a bit of trouble getting it to work in my personal Dev Org.
your code only replies true when u execute it instead use System.debug(s2.Contains(4) )in if statement and then write System.debug(4); inside ua if it'll work
hey Shrey here is the program ,have a look. public class findCommon { public static void common(list l1,list l2,list l3) { set s1=new set(l1); set s2=new set(l2); set s3=new set(l3); s1.retainall(s2); s1.retainall(s3); System.debug(s1); } } //save the above typed class and open anonymous window for execution (ctrl+e) // type the below code in anonymous window and run it. list l1=new list{1,4,7}; list l2=new list{2,5,3,6,4,8,9}; list l3=new list{9,5,2,7,4}; findCommon.common(l1,l2,l3); we can do same for the 2nd Example :) thanks and Regards, Amit Jha.
public class Practices{ public static Integer unique(List l1, List l2, List l3){ Integer unique = 0; for (Integer i : l1){ if (l2.contains(i) && l3.contains(i)) unique = i; } return unique; } }
public void intersection(List l1, List l2, List l3){ Set s = new Set(l1); s.retainAll(l2); s.retainAll(l3); System.debug(s); }
public void list1(){ List l1 = new List{1,4,8,7}; List l2 = new List{2,5,3,6,4,8,9}; List l3 = new List{9,5,2,7,4}; intersection(l1, l2, l3); }
public void list2(){ List l1 = new List{15,19,20,22,29,65,75}; List l2 = new List{19,22,24,26,45,65,70}; List l3 = new List{2,4,9,18,19,22,65,75}; intersection(l1, l2, l3); } }
Ok. Here's my best shot at the 1st example. List l1 = New List {1,4,7,8}; List l2 = New List {2,5,3,6,4,8,9}; List l3 = New List {1,4,7,8}; Set s2= new Set (); s2.addall (l1); s2.addall (l2); s2.addall (l3); System.debug(s2.Contains(4)); Can you tell me if this is right or give me a hint if it's wrong? I think I need to use ContainsAll but I was having a bit of trouble getting it to work in my personal Dev Org.
@@xJDPTGx contains method returns a boolean value that is either true or false.. Here in your answer it returns true as s2.contains(4) mean whether value 4 is available in the set or not
public static List findAllCommon(List a, List b, List c) { List common = new List(); List finallst = new List(); for(Integer x:a) { if(b.Contains(x)) { common.add(x); } } for(Integer y:common) { if(c.Contains(y)) { finallst.add(y); } } return finallst; } This method returns the List of elements which are common in the three Lists. Please let me know your views on this so that i can correct myself
Example #2 List l1 = New List {15,19,20,22,29,65,75}; List l2 = New List {19,22,24,26,45,65,70}; List l3 = New List {2,4,9,18,19,22,65,75}; Set s2= new Set (); s2.addall (l1); s2.addall (l2); s2.addall (l3); System.debug(s2.Contains(19,22,65));
Hi, here my solution for the test. list l1= new list{1,4,7,8}; list l2= new list{2,5,3,6,4,8,9}; list l3 = new list{9,5,2,7,4}; set s1= new set(); s1.addAll(l1); s1.addAll(l2); s1.addall(l3); s1.retainAll(l1); s1.retainAll(l2); s1.retainAll(l3); system.debug(s1);
public List FindingCommonElementFromLists(List l1, List l2, List l3) { List commonElement=new List(); for (integer i = 0; i < l1.size(); i++) { if (l2.Contains(l1[i]) && l3.Contains(l1[i])) { commonElement.Add(l1[i]); } } return commonElement; }
Hi Shrey, I am a newbie in Salesforce. I tried to solve the question in this chapter, but didn't understand the meaning of O(n). Below is my code, its a bit messy. Do let me know if this is correctly done: Class: public class ShreyTest { public static void MyMethod(List L1, List L2, List L3){
Set s1 = new Set(L1); Set s2 = new Set (s1); Set s3 = new Set (s1); system.debug('First Check'); system.debug('First list has: ' +s1); system.debug('Second list has: ' + L2); s1.removeAll(L2); system.debug('Elements unique to List 1: ' +s1); s3.removeAll(s1); system.debug('Elements common to List 1 and 2: ' +s3); system.debug('************************'); Set st1 = new Set(L2); Set st2 = new Set (st1); Set st3 = new Set (st1); system.debug('Second Check'); system.debug('Second List has: ' +st1); system.debug('Third List has: ' +L3); st1.removeAll(L3); system.debug('Elements unique to List 2: ' +st1); st3.removeALL(st1); system.debug('Elements common to List 2 and 3: ' +st3); system.debug('************************'); system.debug('3nd loop'); Set sr1 = new Set(s3); Set sr2 = new Set (s3); Set sr3 = new Set (st3); sr2.removeALL(sr3); system.debug(sr2); sr1.removeALl(sr2); system.debug('Elements unique in all 3 lists: ' +sr1); } } To call this method, in console I write: List Lst1 = new List{15,19,20,22,29,65,75}; List Lst2 = new List {19,22,24,26,45,65,70}; List Lst3 = new List {2,4,9,18,19,22,65,75}; ShreyTest.MyMethod(Lst1, Lst2, Lst3);
public class Hulk
{
Public Static void Check(Set s1,Set s2,Set s3)
{
s2.retainAll(s1);
s3.retainAll(s2);
System.debug(s3);
}
}
AMAZING!
You are the next JUNIOR HULK, Venkatesh. Congratulations !! Reach me out on salesforcehulk@gmail.com to get your JUNIOR HULK t-shirt.
Best answer it is
Hi, could you please provide the calling method to be written in anonymous window for this too
Can someone explain how to pass these three list values to the method in the anonymous window
public class SetChallenge1 {
public void checking(List l1,List l2,List l3){
set s= new set();
s.addall(l2);
s.retainAll(l1);
s.retainAll(l3);
System.debug('Common Elements' + s);
}
}
Nice soln 👍
how to pass value in checking method when call
Hey Shrey. I don’t see any video on Map. I believe 50% of usage would be a Map in SF.
@Salesforce Hulk Hello Shrey, Hope you are doing well.
I'm a beginner in salesforce and watching Apex programming videos and the 'MAP' collection is missing in the playlist.
Could you please add MAP video to this playlist so we can complete the collection part?
please add because your teaching way is very learnable for us and this missing since last 2 years
Thanks
Hey...your vedios are really great for beginners like me...i request you to explain flows from beginner to expert level...
Can you pls share the Difference b/w clear and remove all
is sObject is generic type which will store all types of data right ?, then whey we are using interger, string data type for storing integer and string values ?...Please correct me if i wrong
In one line declaration of sets in {} what is method ? always add ??
Thank you bro 😊
Thanks so much for this! I needed It.
Hi Hulk, I just started watching your videos it's really awesome...
Pls update with new videos....you are doing great....hats off.....
Hi Shrey.. Could you please make a session on apex triggers.. It would be really really helpful. though there are no. of videos on triggers, i believe your explanation will be perfect, and makes one to understand it in a very clear way.
list l1 = new list {1,4,7,8};
list l2 = new list {2,5,3,6,4,8,9};
list l3 = new list {9,5,2,7,4};
set sn = new set ();
sn.addall(l3);
System.debug(sn.retainAll(l1));
system.debug(sn); //common b/w l3 and l1
System.debug(sn.retainAll(l2));
system.debug(sn); //common b/w l3 and l2 also l1
//Complexity :- O(1)
Hey Salesforce hulk i have q question, whenever i try to execute different commands which i have learned from you it keep giving me the error of " Method does not exist or incorrect signature" , then after that it has happened quite a lot now, where i try to add custom feild in account by __c , .ADDALL or .contians . i have tried everything even copying the code which you used in your example. DID'NT WORK!!
please guide what is the real issue here?
Apex Class With commonElements() method
public class SetCommonValues {
public void commonElements(Set s1, Set s2, Set s3){
Set commonElements = new Set();
commonElements.addAll(s1);
commonElements.addAll(s2);
commonElements.addAll(s3);
commonElements.retainAll(s1);
commonElements.retainAll(s2);
commonElements.retainAll(s3);
System.debug('Common Elements : ' + commonElements);
}
}
How to call from Anonymous Window
SetCommonValues s = new SetCommonValues();
Set s1 = new Set{15,19,20,22,29,65,75};
Set s2 = new Set{19,22,24,26,45,65,70};
Set s3 = new Set{2,4,9,18,19,22,65,75};
s.commonElements(s1,s2,s3);
Result : 22:56:09:004 USER_DEBUG [15]|DEBUG| Common Elements : {19, 22, 65}
Great, Shubham. Very neat code but you got a little late, better luck next time though. :) :)
public static void SetQuery(List lst1,List lst2, List lst3){
// To find the list of common elements in three Lists recieved as an argument
// Ex 1) lst1 = {1,4,7,8} lst2={2,5,3,6,4,8,9} lst3={9,5,2,7,4}
// Required Output to be List Comm = {4}
List Comm = new List();
for (integer i = 0; i
Nice Sir, I love the way you teach ;
public class Practices {
public static Set unique(List l1, List l2, List l3){
Set s = new Set();
for (Integer i : l1){
if (l2.contains(i) && l3.contains(i))
s.add(i);
}
return s;
}
}
Hi, will u please demonstrate example of Nested Map, List and Set....
The method:
public class Junior_hulk {
public static Set commonInt(List l1,List l2,List l3)
{
set s=new set();
s.addall(l1);
s.retainall(l2);
s.retainall(l3);
system.debug('ommon set of integers-->'+(s));
return s;
}
}
Calling the method:
list l1=new List{1,4,7,8};
list l2=new List{2,5,3,6,4,8,9};
list l3=new List{9,5,2,7,4};
set s_new=new set();
s_new=Junior_hulk.commonInt(l1,l2,l3);
system.debug(s_new);
Hi Shrey, Can you please upload more development tutorials.
Ok. Here's my best shot at the 1st example:
List l1 = New List {1,4,7,8};
List l2 = New List {2,5,3,6,4,8,9};
List l3 = New List {1,4,7,8};
Set s2= new Set ();
s2.addall (l1);
s2.addall (l2);
s2.addall (l3);
System.debug(s2.Contains(4));
Can you tell me if this is right or give me a hint if it's wrong? I think I need to use ContainsAll but I was having a bit of trouble getting it to work in my personal Dev Org.
your code only replies true when u execute it instead use System.debug(s2.Contains(4) )in if statement and then write System.debug(4); inside ua if it'll work
Eagerly waiting for map video
Coming up next!
@@SalesforceHulk Please upload Map concept as well . thanks !
hey Shrey here is the program ,have a look.
public class findCommon {
public static void common(list l1,list l2,list l3)
{
set s1=new set(l1);
set s2=new set(l2);
set s3=new set(l3);
s1.retainall(s2);
s1.retainall(s3);
System.debug(s1);
}
}
//save the above typed class and open anonymous window for execution (ctrl+e)
// type the below code in anonymous window and run it.
list l1=new list{1,4,7};
list l2=new list{2,5,3,6,4,8,9};
list l3=new list{9,5,2,7,4};
findCommon.common(l1,l2,l3);
we can do same for the 2nd Example :)
thanks and Regards,
Amit Jha.
Correct!
why you have used this line s1.retainall(s2) and s1.retainall(s3) can you please explain??
Please provide challenge solution in next session... and as like before u explained it very clearly 😍
Bhai..when u r launching next videos..we are eagerly waiting..
Will you be posting more development videos covering topics like triggers, VF, testing and all that?
Yes Yes Yes!
public class Practices{
public static Integer unique(List l1, List l2, List l3){
Integer unique = 0;
for (Integer i : l1){
if (l2.contains(i) && l3.contains(i))
unique = i;
}
return unique;
}
}
Hi please make more videos on Salesforce development part
Shrey, you did not told who was the winner of last Junior Hulk Challenge, that is on List In Apex Video
public class List_Manipulation {
public void intersection(List l1, List l2, List l3){
Set s = new Set(l1);
s.retainAll(l2);
s.retainAll(l3);
System.debug(s);
}
public void list1(){
List l1 = new List{1,4,8,7};
List l2 = new List{2,5,3,6,4,8,9};
List l3 = new List{9,5,2,7,4};
intersection(l1, l2, l3);
}
public void list2(){
List l1 = new List{15,19,20,22,29,65,75};
List l2 = new List{19,22,24,26,45,65,70};
List l3 = new List{2,4,9,18,19,22,65,75};
intersection(l1, l2, l3);
}
}
sir, could you please help for admin exam.
Should I put the solution in the comments here for the Junior Hulk thing?
Yes.
Ok. Here's my best shot at the 1st example.
List l1 = New List {1,4,7,8};
List l2 = New List {2,5,3,6,4,8,9};
List l3 = New List {1,4,7,8};
Set s2= new Set ();
s2.addall (l1);
s2.addall (l2);
s2.addall (l3);
System.debug(s2.Contains(4));
Can you tell me if this is right or give me a hint if it's wrong? I think I need to use ContainsAll but I was having a bit of trouble getting it to work in my personal Dev Org.
@@xJDPTGx contains method returns a boolean value that is either true or false.. Here in your answer it returns true as s2.contains(4) mean whether value 4 is available in the set or not
Pls make fast Yar Dev series and also show glimpse I ide
public static List findAllCommon(List a, List b, List c)
{
List common = new List();
List finallst = new List();
for(Integer x:a)
{
if(b.Contains(x))
{
common.add(x);
}
}
for(Integer y:common)
{
if(c.Contains(y))
{
finallst.add(y);
}
}
return finallst;
}
This method returns the List of elements which are common in the three Lists. Please let me know your views on this so that i can correct myself
Example #2
List l1 = New List {15,19,20,22,29,65,75};
List l2 = New List {19,22,24,26,45,65,70};
List l3 = New List {2,4,9,18,19,22,65,75};
Set s2= new Set ();
s2.addall (l1);
s2.addall (l2);
s2.addall (l3);
System.debug(s2.Contains(19,22,65));
Hi, here my solution for the test.
list l1= new list{1,4,7,8};
list l2= new list{2,5,3,6,4,8,9};
list l3 = new list{9,5,2,7,4};
set s1= new set();
s1.addAll(l1);
s1.addAll(l2);
s1.addall(l3);
s1.retainAll(l1);
s1.retainAll(l2);
s1.retainAll(l3);
system.debug(s1);
public List FindingCommonElementFromLists(List l1, List l2, List l3)
{
List commonElement=new List();
for (integer i = 0; i < l1.size(); i++)
{
if (l2.Contains(l1[i]) && l3.Contains(l1[i]))
{
commonElement.Add(l1[i]);
}
}
return commonElement;
}
next videos plzz?
public class FindCommon {
public static Set findCommon(List l1,List l2,List l3)
{
Set commonSet = new Set();
List maxList = l1.size() > l2.size() ? (l1.size() > l3.size() ? l1 : l3) : (l2.size() > l3.size() ? l2 : l3);
for(Integer i=0;i
Can i know when the next video comes in development tutorial series?
Hi Shrey,
I am a newbie in Salesforce.
I tried to solve the question in this chapter, but didn't understand the meaning of O(n).
Below is my code, its a bit messy. Do let me know if this is correctly done:
Class:
public class ShreyTest {
public static void MyMethod(List L1, List L2, List L3){
Set s1 = new Set(L1);
Set s2 = new Set (s1);
Set s3 = new Set (s1);
system.debug('First Check');
system.debug('First list has: ' +s1);
system.debug('Second list has: ' + L2);
s1.removeAll(L2);
system.debug('Elements unique to List 1: ' +s1);
s3.removeAll(s1);
system.debug('Elements common to List 1 and 2: ' +s3);
system.debug('************************');
Set st1 = new Set(L2);
Set st2 = new Set (st1);
Set st3 = new Set (st1);
system.debug('Second Check');
system.debug('Second List has: ' +st1);
system.debug('Third List has: ' +L3);
st1.removeAll(L3);
system.debug('Elements unique to List 2: ' +st1);
st3.removeALL(st1);
system.debug('Elements common to List 2 and 3: ' +st3);
system.debug('************************');
system.debug('3nd loop');
Set sr1 = new Set(s3);
Set sr2 = new Set (s3);
Set sr3 = new Set (st3);
sr2.removeALL(sr3);
system.debug(sr2);
sr1.removeALl(sr2);
system.debug('Elements unique in all 3 lists: ' +sr1);
}
}
To call this method, in console I write:
List Lst1 = new List{15,19,20,22,29,65,75};
List Lst2 = new List {19,22,24,26,45,65,70};
List Lst3 = new List {2,4,9,18,19,22,65,75};
ShreyTest.MyMethod(Lst1, Lst2, Lst3);
Hello sir, I want to be a junior Hulk
Just wait for another contest.
Map?
public class Hulk
{
Public Static void Check(Set s1,Set s2,Set s3)
{
s2.retainAll(s1);
s3.retainAll(s2);
System.debug(s3);
}
}
Correct