• cjprad
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi, I need assistance in providing code coverage for the below code in bold.

Apex Class:
public class AddListToCampaignFlowAction {
                
       @InvocableMethod(label='Add List to Campaign Apex Action' description='Provide List Id and Campaign Id')
       public static void PassListIdApexMethod(AddListToCampaignApexActionRequest[] requests) { 

          if(requests.size() == 0) { return; }
          else {
              Id ListId = requests[0].ListId;
              Id CampaignId = requests[0].CampaignId;
              List<CampaignMember> existingCampMembers = new List<CampaignMember>();
              existingCampMembers = [SELECT Id, ContactId FROM CampaignMember WHERE CampaignId=:CampaignId];
              List<Contact> existingContacts = new List<Contact>();
              for(CampaignMember cm : existingCampMembers ) {
                  Contact con = new Contact();
                  con.Id = cm.ContactId;
                  existingContacts.add(con);

              }
              Map<Id,Contact> existingContactsMap = new Map<Id,Contact>(existingContacts);

              List<CampaignMember> campmembers = new List<CampaignMember>();
              List<WVU_PO_List_Affiliation__c> listAffiliations = new List<WVU_PO_List_Affiliation__c>();
              listAffiliations = [SELECT Id, WVU_PO_Contact__c FROM WVU_PO_List_Affiliation__c WHERE WVU_PO_List__c=:ListId AND Contact_Active__c = TRUE];
                        
              for(WVU_PO_List_Affiliation__c listAffiliation : listAffiliations ) {
                if(existingContactsMap.containsKey(listAffiliation.WVU_PO_Contact__c)) {continue;}
                else {
                    CampaignMember campmem = new CampaignMember();
                    campmem.CampaignId = CampaignId;
                    campmem.ContactId = listAffiliation.WVU_PO_Contact__c;
                    campmem.Status = 'Invited';
                    campmembers.add(campmem);

                }
              }                
              insert campmembers;
          }
      }
      
      public class AddListToCampaignApexActionRequest {
          
          @InvocableVariable(required=true)
          public Id ListId;
          
          @InvocableVariable(required=true)
          public Id CampaignId;
          
      }
}

Test Class
@isTest(SeeAllData=true)

public class AddListToCampaignFlowActionTest {
    
    static testMethod void testAddListToCampaignFlowAction() {
        
        //Create test contact
        Contact con = new Contact();
        con.LastName = 'TestListCampaign';
        insert con;
        Contact testCon = [SELECT Id, LastName FROM Contact WHERE LastName = 'TestListCampaign' ORDER BY LastModifiedDate DESC LIMIT 1];

        //Create test list
        WVUPO_List__c tList = new WVUPO_List__c();
        tList.Name = 'TestList';
        insert tList;
        WVUPO_List__c testList = [SELECT Id, Name FROM WVUPO_List__c WHERE Name = 'TestList' ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create test list affiliation
        WVU_PO_List_Affiliation__c tListAff = new WVU_PO_List_Affiliation__c();
        tListAff.WVU_PO_Contact__c = testCon.Id;
        tListAff.WVU_PO_List__c = testList.Id;
        insert tListAff;
        WVU_PO_List_Affiliation__c testListAff = [SELECT Id FROM WVU_PO_List_Affiliation__c WHERE WVU_PO_Contact__c =:testCon.Id AND WVU_PO_List__c =:testList.Id ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create test campaign
        Campaign camp = new Campaign();
        camp.Name = 'TestCampaign';
        insert camp;
        Campaign testCamp = [SELECT Id, Name FROM Campaign WHERE Name = 'TestCampaign' ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create array of requests
        AddListToCampaignFlowAction.AddListToCampaignApexActionRequest testRequest = new AddListToCampaignFlowAction.AddListToCampaignApexActionRequest();
        List<AddListToCampaignFlowAction.AddListToCampaignApexActionRequest> testRequests = new List<AddListToCampaignFlowAction.AddListToCampaignApexActionRequest>();
        testRequest.ListId = testList.Id;
        testRequest.CampaignId = testCamp.Id;
        testRequests.add(testRequest);
        
        //Start test
        //Test.startTest();
        AddListToCampaignFlowAction.PassListIdApexMethod(testRequests);
        
        //Test.stopTest();
    }
}
  • March 20, 2019
  • Like
  • 0
Hi All, I want to create a custom button on Contact List View that will enable me to link multiple contacts to a custom object. The page following the button should have two fields from the custom object, one lookup and one picklist. I am reading that it is possible through Wrapper Class, but I am new to Salesforce Development. Most of the online resources it seems are for creating a separate page, but I want to use custom button on a list view. Any suggestions on how I can start will be really appreciated.

I eventually want to move these codes to production. Will there be any issues and what concerns I need to consider regarding test class and code coverage.

Thanks, Chetan
  • February 08, 2018
  • Like
  • 0
We use a managed package solution in our org. Our org has 3 user groups. The org-wide default for a custom object which is a component of the mangaged package is controlled by Contact access which is Public Read/Write for internal users (as in the UI). Now, I imagine the users from one group should not be seeing the records created or owned by other groups. Unfortunately, I cannot test. Is there any chance that there is Apex sharing involved in this to implement the required sharing of records being visible only within the group? Main confusion is since Apex sharing does not work with Standard objects (Contact), however, the object in question is a custom object.
  • October 10, 2017
  • Like
  • 0
Hi, I need assistance in providing code coverage for the below code in bold.

Apex Class:
public class AddListToCampaignFlowAction {
                
       @InvocableMethod(label='Add List to Campaign Apex Action' description='Provide List Id and Campaign Id')
       public static void PassListIdApexMethod(AddListToCampaignApexActionRequest[] requests) { 

          if(requests.size() == 0) { return; }
          else {
              Id ListId = requests[0].ListId;
              Id CampaignId = requests[0].CampaignId;
              List<CampaignMember> existingCampMembers = new List<CampaignMember>();
              existingCampMembers = [SELECT Id, ContactId FROM CampaignMember WHERE CampaignId=:CampaignId];
              List<Contact> existingContacts = new List<Contact>();
              for(CampaignMember cm : existingCampMembers ) {
                  Contact con = new Contact();
                  con.Id = cm.ContactId;
                  existingContacts.add(con);

              }
              Map<Id,Contact> existingContactsMap = new Map<Id,Contact>(existingContacts);

              List<CampaignMember> campmembers = new List<CampaignMember>();
              List<WVU_PO_List_Affiliation__c> listAffiliations = new List<WVU_PO_List_Affiliation__c>();
              listAffiliations = [SELECT Id, WVU_PO_Contact__c FROM WVU_PO_List_Affiliation__c WHERE WVU_PO_List__c=:ListId AND Contact_Active__c = TRUE];
                        
              for(WVU_PO_List_Affiliation__c listAffiliation : listAffiliations ) {
                if(existingContactsMap.containsKey(listAffiliation.WVU_PO_Contact__c)) {continue;}
                else {
                    CampaignMember campmem = new CampaignMember();
                    campmem.CampaignId = CampaignId;
                    campmem.ContactId = listAffiliation.WVU_PO_Contact__c;
                    campmem.Status = 'Invited';
                    campmembers.add(campmem);

                }
              }                
              insert campmembers;
          }
      }
      
      public class AddListToCampaignApexActionRequest {
          
          @InvocableVariable(required=true)
          public Id ListId;
          
          @InvocableVariable(required=true)
          public Id CampaignId;
          
      }
}

Test Class
@isTest(SeeAllData=true)

public class AddListToCampaignFlowActionTest {
    
    static testMethod void testAddListToCampaignFlowAction() {
        
        //Create test contact
        Contact con = new Contact();
        con.LastName = 'TestListCampaign';
        insert con;
        Contact testCon = [SELECT Id, LastName FROM Contact WHERE LastName = 'TestListCampaign' ORDER BY LastModifiedDate DESC LIMIT 1];

        //Create test list
        WVUPO_List__c tList = new WVUPO_List__c();
        tList.Name = 'TestList';
        insert tList;
        WVUPO_List__c testList = [SELECT Id, Name FROM WVUPO_List__c WHERE Name = 'TestList' ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create test list affiliation
        WVU_PO_List_Affiliation__c tListAff = new WVU_PO_List_Affiliation__c();
        tListAff.WVU_PO_Contact__c = testCon.Id;
        tListAff.WVU_PO_List__c = testList.Id;
        insert tListAff;
        WVU_PO_List_Affiliation__c testListAff = [SELECT Id FROM WVU_PO_List_Affiliation__c WHERE WVU_PO_Contact__c =:testCon.Id AND WVU_PO_List__c =:testList.Id ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create test campaign
        Campaign camp = new Campaign();
        camp.Name = 'TestCampaign';
        insert camp;
        Campaign testCamp = [SELECT Id, Name FROM Campaign WHERE Name = 'TestCampaign' ORDER BY LastModifiedDate DESC LIMIT 1];
        
        //Create array of requests
        AddListToCampaignFlowAction.AddListToCampaignApexActionRequest testRequest = new AddListToCampaignFlowAction.AddListToCampaignApexActionRequest();
        List<AddListToCampaignFlowAction.AddListToCampaignApexActionRequest> testRequests = new List<AddListToCampaignFlowAction.AddListToCampaignApexActionRequest>();
        testRequest.ListId = testList.Id;
        testRequest.CampaignId = testCamp.Id;
        testRequests.add(testRequest);
        
        //Start test
        //Test.startTest();
        AddListToCampaignFlowAction.PassListIdApexMethod(testRequests);
        
        //Test.stopTest();
    }
}
  • March 20, 2019
  • Like
  • 0
Hi All,
I have a Visualforce page which I want to use in Lightning experience. The page has few lookup fields. Is there a way to embed or code to enable lightning-native lookup fields that will give the ability to not only search for the lookup item but will also give the option to create new lookup record if you want to, like in the image below? There are few lightning lookup components and resources out there but I doubt they give this option. Any help will be really appreciated. Thanks!User-added image
Hi All,

I would like to query all SObject recrods owned by specific user, can you please guide me how can we do that?

My requirement:
We would like to deactivate the more Users in our org, hence instead of transfering the records for each user manually, require to implement through apex that all records will transfer from one User  to another on button click. any alternative suggestion would be appriciated..

Thanks
Sivasankar.