Hello I have the following method but I need to compare one map with another map and then if they match carry out some action. (I need the ID as I may need to delete or update my record if it matches.

public static void manageTheBoards (){
    // manages on how we deal with the board updates
    map<string, trello_boards__C> myTrelloBoards = new map<string, trello_boards__C>(
                        [SELECT Trello_Board_Id__c , name, id 
                        FROM Trello_Boards__c

    System.debug('My local map of trello boards =' + myTrelloBoards);
    System.debug('The Returned Map Contains: ' + boardNameWithId);

    //for (string boardName : boardNameWithID.keyset()) {
        //if (boardName == ??????()) {

        //System.debug('My id is =' +boardName);
        //System.debug('i Match = ');

Basically my returned values look like this:

MyTrelloBoards Example

my local map of trello boards ={a2n0C000000AK8jQAG=Trello_Boards__c:{Trello_Board_Id__c=5d8b33d13af8d42de7d1740f, Name=GMS Sprints - Backlog, Id=a2n0C000000AK8jQAG}, a2n0C000000AK8oQAG=Trello_Boards__c:{Trello_Board_Id__c=5cc2bdcb05ebdc5c1525844b, Name=GMS Sprints - 

TheBoardNameWithID Example

The Returned Map Contains: {5b4777684a24477be17ce26c=Core Funding Products Backlogs, 5bd18776b162785b6562d556=Core Funding Products/GMS, 5c2e1c4953081e8b3d41b6a4=ULD Library, 5c920af43e392e71a056f5ff=Core Products Sprints: DOING, 5cbeefd33075c0640fa4d480=Core products: Backlog, 5cc2bdcb05ebdc5c15258

I think I need to change the map layout for the My TrelloBoards to be able to compare but it somebody could help that would be fab.

Happy to change if need be.

  • 2
    Can you add a little more detail about what the desired output of the comparison is? Are you trying to identify a delta between the Trello Ids of the two maps? – David Reed Oct 11 '20 at 15:18
  • Yes so I want to compare the I’d from both maps – WhiteFusion Oct 11 '20 at 16:29

You can check if one map containsKey() from the other map and perform your logic.

Something like this should work for your code:

for (string boardId: : myTrelloBoards.keyset()){
        if (boardNameWithId.containsKey(boardId)) {
        //Do something 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.