SalesforceLabs / survey-force

85 stars 61 forks source link

Ensure unique response submission by Guest Users #90

Closed arorard closed 3 years ago

arorard commented 3 years ago

How can the duplicate Survey responses for a case or/and contact by a Guest user be prevented? In other words, survey response for a case or contact should be submitted once and only once.

It seems this check can work for userType!='Guest' currently and if it needs to be enforced for Guest user then it may require code changes.

If there is a configuration to meet the requirements currently, please let me know; else consider this enhancement in future.

thanks,

jrattanpal commented 3 years ago

There is no configuration or code currently that meets the requirement. For non-guest users, it's the code block starting at line#382 in https://github.com/SalesforceLabs/survey-force/blob/master/force-app/main/default/classes/ViewSurveyController.cls.

That code needs to be replicated somehow for Guest users. I can add that as a feature request but I am not sure when this can be implemented.

If we were to implement it then what will be the logic?

If we do implement it, it will be behind a custom metadata type which will be off by default because we don't want to impact existing implementations.

arorard commented 3 years ago

@jrattanpal

Thanks for replying!

I was thinking a possible solution could introduce a new custom field in Survey__c object to indicate that response should be processed once per case or contact , and viewSurveyController class can check this field is true at line#382 (with an OR operator with Guest user condition) and let the existing logic check if a response was submitted for the case or contact. This new field can have default value as false and so it should not disturb the existing surveys.

Let me know your thoughts.

thanks,

jrattanpal commented 3 years ago

That's an interesting solution. Maybe a combination?

If Custom field is empty/zero then unlimited. But if not empty/zero then check if that number is < rollup summary field then store the result. If > = then show a message.

Or maybe better yet, don't even render survey at all

arorard commented 3 years ago

That definitely makes it better and flexible !! Awesome !

jrattanpal commented 3 years ago

I will add it to feature request. But I am not sure when I'd be able to work on it.

dschach commented 3 years ago

This is a good feature request. We would need a field to say that the survey can only be taken once per combination of case/contact (so a contact could take it multiple times if they have multiple cases). We may start tracking the Guest user as the user who takes the survey, so we could implement this with that code.

jrattanpal commented 3 years ago

@dschach This can be achieved without code (rollup summary and flow). Should we write code for this?

dschach commented 3 years ago

I think it's best to use code so we can put in complex logic. I'm looking at different rules for anonymous vs user-linked for internal, and whether or not to use Case and Contact for internal as well. It's pretty complex logic; let's put it in the backlog for now. I'm working on simplifying the survey rendering code (removing unnecessary lines from SFQuestion wrapper class) and making sure that the flexipage won't give more errors due to the related record detail component.

jrattanpal commented 3 years ago

Feature logged at https://github.com/SalesforceLabs/survey-force/issues/123