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
WhiteFusion17WhiteFusion17 

Compare Values from Two Maps

Basically I need to compare the ID value from map to another but the returned map from the SOQL will not work so im trying to build a new map with the Trello_board_ID__C as the key and the name as the value.

But I cannot get it to work, It looks like the GET will only work with the key so this is the reason I think my code returns a null value on the compareTrelloBoard map.
 
public static void manageTheBoards (){ //will need to change back to private after testing
        // manages on how we deal with the board updates
        Map<string, trello_boards__C> myTrelloBoardsMap = new Map<string, trello_boards__C>(
                                                [SELECT  Id, Trello_Board_Id__c , name
                                                FROM Trello_Boards__c
                                                ]);

        System.debug('My Trello Boards Map = ' +myTrelloBoardsMap);

        map<string, string> compareTrelloBoard = new map <string, string>();

        for (string key : myTrelloBoardsMap.keyset()) {
            compareTrelloBoard.put(String.valueOf(myTrelloBoardsMap.get('Trello_Board_Id__c')),String.valueOf(myTrelloBoardsMap.get('Name')));
        }


        //System.debug('myTrelloboards = ' + myTrelloBoards);
        System.debug('boardNameWithID = ' + boardNameWithId);
        System.debug('MyTrello Boards = ' + compareTrelloBoard);

        //for (string boardName : boardNameWithID.keyset()) {
            //if (!myTrelloBoards.containsKey(boardName)) {
            }
        }

Basically I want to convert my myTrelloBoardsMap to a <string, string> map with the trello_board_id__C as the key and the Name as the value.
I can then use this to compare the lists and update / delete / create new values in my salesforce list if they match or don't match
Andrew GAndrew G
remember that the map in this case is <Id, sObject>

Therefore the command 
myTrelloBoardsMap.get(key) will return an sObject, not a string.

so try a conversion like:
for (string key : myTrelloBoardsMap.keyset()) {
            compareTrelloBoard.put(
              String.valueOf( myTrelloBoardsMap.get(key).Trello_Board_Id__c),
              String.valueOf( myTrelloBoardsMap.get(key).Name)
            );
        }
in this way you are accessing the field within the sObject

regards
Andrew

p.s. i have just  broken it over the multiple lines to make it easier to read and cound brackets  ;-)