• prashant rishi 6
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi, i' m trying to populate a <String, Sobject> map but when I try to take only the last record
My code :
 
private void matchCampaigns(Map<Integer, SObject> records, Map<String, SObject> recordsToUpdate){
        
        List<CampaignMember> matchingCampaignMembers = new List<CampaignMember>();
        List<CampaignMember> matchMember = new List<CampaignMember>();
        Set<Id> contactIds = new Set<Id>();
        Set<Id> campaignIds = new Set<Id>();
        
         List<Sobject> recordsToGet = records.values();
                        system.debug(recordsToGet);
                        for(Sobject obj : recordsToGet){
                            
                            Id IdContact = (Id)obj.get('ContactId');
                            Id IdCampaign = (Id)obj.get('CampaignId');
                            
                            contactIds.add(IdContact);
                            campaignIds.add(IdCampaign);
                            
                                                                           
                        }
        system.debug(contactIds);
                            system.debug(campaignIds);
                        
                        matchingCampaignMembers = [Select id,Status 
                 from CampaignMember 
                 where ContactId IN : contactIds and CampaignId IN : campaignIds];
        system.debug('My Match List ' +matchingCampaignMembers);
        
        for(Sobject oh : matchingCampaignMembers ){
            
             recordsToUpdate.put('Id', oh);
            
            
        }
        system.debug('recordsToUpdate ' +recordsToUpdate);
                        
        
    }

as you see from the debug there are not the three records found and inserted in the "matchingCampaignMembers" list. 
what is going wrong?
I would like all the records found to be there.

Debug
apex for below scenario :

We have received list of duplicates and from that list we want to remove the duplicate on basis of name,email and phone number ? 



 
Hi, i' m trying to populate a <String, Sobject> map but when I try to take only the last record
My code :
 
private void matchCampaigns(Map<Integer, SObject> records, Map<String, SObject> recordsToUpdate){
        
        List<CampaignMember> matchingCampaignMembers = new List<CampaignMember>();
        List<CampaignMember> matchMember = new List<CampaignMember>();
        Set<Id> contactIds = new Set<Id>();
        Set<Id> campaignIds = new Set<Id>();
        
         List<Sobject> recordsToGet = records.values();
                        system.debug(recordsToGet);
                        for(Sobject obj : recordsToGet){
                            
                            Id IdContact = (Id)obj.get('ContactId');
                            Id IdCampaign = (Id)obj.get('CampaignId');
                            
                            contactIds.add(IdContact);
                            campaignIds.add(IdCampaign);
                            
                                                                           
                        }
        system.debug(contactIds);
                            system.debug(campaignIds);
                        
                        matchingCampaignMembers = [Select id,Status 
                 from CampaignMember 
                 where ContactId IN : contactIds and CampaignId IN : campaignIds];
        system.debug('My Match List ' +matchingCampaignMembers);
        
        for(Sobject oh : matchingCampaignMembers ){
            
             recordsToUpdate.put('Id', oh);
            
            
        }
        system.debug('recordsToUpdate ' +recordsToUpdate);
                        
        
    }

as you see from the debug there are not the three records found and inserted in the "matchingCampaignMembers" list. 
what is going wrong?
I would like all the records found to be there.

Debug
how to bypass trigger when we insert record through data loader
  • August 07, 2019
  • Like
  • 1