Publishing a Survey

Publishing indicates a survey is ready to be completed by end users. Publishing locks the survey restricting editing to survey properties and questions. The following processes occur when a survey is published using the default batch.

Administrators can download a zip file containing the results of a publishing job. The zip file contains two CSV files. The first file has one row representing the details of the publishing job. The second file contains a row for every target account assigned. If a target account was not assigned, the file includes a reason why the assignment failed. This can be used to troubleshoot Survey publishing if the target account assignments are not as expected.

Administrators can abort a job in progress or republish a survey. After a job is aborted, the Survey’s status reverts to the previous status – either Development_vod or Published_vod.

Selecting Republish re-runs the Survey publish job with all the survey targets. The status for the survey changes to Publishing_vod while the job is running and then to Published_vod once it is complete.

Different logic can be applied by creating a batch and pointing the setting to the new batch.

To prevent publishing failures, ensure all users who are within the included User Territories for a survey and could potentially be assigned a survey target record have Read permission to the Survey_Target_vod object.

Veeva Settings for Publishing Surveys

Two Veeva Settings determine which publishing batch is executed when publishing a survey and when to display alerts to end users for Survey Targets nearing their end date:

  • Survey_Publish_Apex_vod - uses the name of the Apex Class used when publishing a survey. If it is blank, which is the default setting, it points to the default batch, Veeva_Batch_Survey_Publish. To use a different publishing batch, enter the name of the batch in this setting.
  • SURVEY_ALERT_THRESHOLD_vod - the value determines the number of days before a Survey Target’s end date to display an alert to the end user on the homepage in CRM for iPad

The VEEVA_BATCH_SURVEY_PUBLISH Apex Class is the default batch referenced in the Survey_Publish_Apex_vod Veeva Setting . When a survey admin selects Publish the default batch is triggered.

MC Engine Publishing

Along with publishing a survey from the survey itself, users can also use the Multichannel engine (MC Engine) to publish surveys. Using Veeva’s MC Engine allows for more than five concurrent jobs to run at the same time.

To publish surveys using Veeva’s MC Engine:

  1. Enter a value of 1 for the Survey_Publish_Apex_vod Veeva Setting.
  2. Ensure the admin user has access to the Survey Administration tab.
  3. Enter and validate the integration user’s credentials. The integration user is used to write back data to the SFDC database after a survey is published.
  4. Grant the integration user edit permission to the following objects:
  • Survey_vod
  • Survey_Target_vod
  • Survey_Question_vod

When publishing surveys using the MC Engine, notification emails are not sent to the administrator.

An error message stating Problem querying for Survey or Survey Targets displays if there are too many concurrent publishing tasks.

Publishing a Survey to a New Target

After a survey is published and locked from edits, new Survey Targets can still be added from the Targets section of the Survey Management screen. When a Survey Target is added, the record status is changed to Development_vod and the Publish to New Targets button displays at the top of the Survey Management screen. Selecting this button re-publishes the survey and the batch only processes the new Survey Target records.

Save Button for Surveys

If a survey is published for multiple end users, the Save button can be removed from the Survey Target Execution screen to prevent one end user from deleting the answers of another before the survey is submitted. Users can submit a Survey Target only once. Once a survey is submitted, the answers cannot be edited.

To remove the Save button, navigate to the appropriate Survey Target record type and remove Saved_vod button from the Selected Values for the Status picklist.

Customizing the Publishing Batch for Surveys

This section includes two code examples of how to use custom publishing logic. These are only examples and need to be tested in individual environments.

Publishing to Users Based on Role

This example assigns target accounts to users by first looking at the Territory_vod field on the survey, and then looking at a custom Role_vod field on the survey. If the org has users with multiple roles within the same territory node and Survey Target records should be published only to users with a particular role, use this method. You should create a custom pick-list for the Survey admins to select the role limit, and to populate this pick-list with values that map to the roles in your org.

  1. Create a map for the UserRole object in init() method:

for (UserRole ur :[Select Id.Name from UserRole] )

{

roleIds.put(ur.Name.ur.Id);

}

  1. Replace the code In the GetUsersForAccounts() method to find the user based on the territory field with the following code snippet assuming the custom field name is Role_dk:

//sample: find the user based on roleid

String roleName = surveyToUpdate.Role_dk__c;

Id roleId = roleIds.get(roleName);

System.debug('role id:' + roleId);

Map<Id,User> activeuserids = null;

if(roleId != null)

activeuserids = new Map<Id,User>([Select Id From User Where Id In :alluserids And IsActive=true And userRoleId = :roleId]);

else

activeuserids = new Map<Id,User>([Select Id From User Where Id In :alluserids And IsActive=true]);

System.debug('activeuserids'+activeuserids);

for(string acctId : acctList)

{

List<String> userids = acct_userids.get(acctId);

if(userids != null && userids.size() > 0){

for(String id : userids)

{

if(activeuserids.keySet().contains(id))

{ acctUserMap.put(acctId,id); }

}

}

}

Publishing to Users Based on Profile

This code example restricts Survey Target assignments by user profile, and also requires a correct mapping of a custom field on Survey_vod object to the name values of the profiles in the org assigning Survey Target records to.

The New Survey Target allows Survey users to select their own target accounts and create new Survey Target records, but does not restrict the ability to add new target accounts to a survey using these custom fields. This function is only able to limit the scope of users who can add target accounts by the Territory_vod field selected on the Survey.

  1. Create a map for the Profile object in inti() method:

for (Profile ur :[Select Id.Name from Profile] )

{

prfileIds.put(ur.Name.ur.Id);

}

 

  1. Replace the code In GetUsersForAccounts() method to find the user based on territory field with the following code snippet assuming the custom field name is Profile_dk:

String profileName = surveyToUpdate.Profile_dk__c;

Id profileId = profileIds.get(profileName);

System.debug('profile id' + profileId);

Map<Id,User> activeuserids = null;

if(profileId!= null)

activeuserids = new Map<Id,User>([Select Id From User Where Id In :alluserids And IsActive=true And ProfileId= :profileId]);

else

activeuserids = new Map<Id,User>([Select Id From User Where Id In :alluserids And IsActive=true]);

for(string acctId : acctList)

{

List<String> userids = acct_userids.get(acctId);

if(userids != null && userids.size() > 0){

for(String id : userids)

{

if(activeuserids.keySet().contains(id)){ acctUserMap.put(acctId,id); }

}

}

}