Skip to main content
added 4 characters in body
Source Link
pjcarly
  • 7.5k
  • 5
  • 37
  • 56

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

// ... do your logic

Here is the documentation for Maps and Sets try to use this as much as possible to reduce the number of script statements you have for manually looping over lists just to check if itvalues exists or not.

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

// ... do your logic

Here is the documentation for Maps and Sets try to use this as much as possible to reduce the number of script statements you have for manually looping over lists just to check if it exists or not.

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

// ... do your logic

Here is the documentation for Maps and Sets try to use this as much as possible to reduce the number of script statements you have for manually looping over lists just to check if values exists or not.

added 428 characters in body
Source Link
pjcarly
  • 7.5k
  • 5
  • 37
  • 56

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c); 

// ... do your logic

.. Here is the documentation for Maps and Sets try to use this as much as possible to reduce the number of script statements you have for manually looping over lists just to check if it exists or not. do your logic

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

... do your logic

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c); 

// ... do your logic

Here is the documentation for Maps and Sets try to use this as much as possible to reduce the number of script statements you have for manually looping over lists just to check if it exists or not.

Source Link
pjcarly
  • 7.5k
  • 5
  • 37
  • 56

If I understand you correctly, you want to check if values exists in lists,

Since you have a unique name, it's best to leverage that uniqueness in combination with a map, you start of by adding all the values in your lists to 2 maps.

Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

... do your logic