SalesforceLabs / survey-force

85 stars 61 forks source link

Many survey taken by user #105

Closed Brisingr75 closed 3 years ago

Brisingr75 commented 3 years ago

Hi,

I just discover your SF component and it's quite great ! I would like to use it internally but it seems it's not possible to fill many times a survey as a user. How can I take off the limit ?

Bonus question : I know that I can link a survey with a contact / case is it possible to link with an opportunity ?

Thanks Steve

jrattanpal commented 3 years ago

Hi,

Thanks for using this app. For your issues: 1) This limitation is for internal users only. Guest users can take a survey as many times as they want. But if you still want your internal users to take a survey multiple times then you can make the following change in your code.

https://github.com/SalesforceLabs/survey-force/blob/master/force-app/main/default/classes/ViewSurveyController.cls Comment lines from 382 to 393

This is the code that does the check prior to user submitting the survey

2) Yes, you can associate a survey to other objects but you need to make changes to the code. I explained this in https://github.com/SalesforceLabs/survey-force/issues/85

Brisingr75 commented 3 years ago

Thanks Jrattanpal for your quick reply. I'm an admin and not a developer so I'm not confortable to change codes inside your app.

Can you guide me (step by step) ? Where I can put an additionnal code in SF ?

For the 1, I just need to change the number (here "0") ? For the 2, I need to add opportunity id like this :

public ViewSurveyController(ViewShareSurveyComponentController controller) { surveyId = Apexpages.currentPage().getParameters().get('id'); mySurvey = [SELECT Id, Thank_You_Linkc FROM Surveyc WHERE Id = :surveyId WITH SECURITY_ENFORCED LIMIT 1];

    caseId   = Apexpages.currentPage().getParameters().get('caId');
    contactId = Apexpages.currentPage().getParameters().get('cId');
    opportunityId = Apexpages.currentPage() .getParameters () .get('oId');
    if(caseId == null || caseId.length()<15){
        caseId = 'none';
    }
    if(contactId == null || contactId.length()<15){
        contactId = 'none';
    }
    if (opportunityId == null || opportunityId.length()<50){
        opportunityId = 'none';
    }
    surveyId = String.escapeSingleQuotes(surveyId);
    caseId = String.escapeSingleQuotes(caseId);
    contactId = String.escapeSingleQuotes(contactId);
    opportunityId = String.escapeSingleQuotes (opportunityId);
    // By default the preview is not showing up
    renderSurveyPreview = 'false';
    init();
}

Any help is appreciate, maybe I ask you too much...

jrattanpal commented 3 years ago

DISCLAIMER: While I do provide the code below, you need to make changes and test it to make sure it's working; this code hasn't been tested. You also should do this change in sandbox, test and then move to production via change set.

FOr 1), You can comment those lines like below in https://github.com/SalesforceLabs/survey-force/blob/master/force-app/main/default/classes/ViewSurveyController.cls

/* COMMENT START
if(anonymousAnswer != 'Anonymous')
        {
            //If survey is taken by Contact OR Case already then no need to take it again
            List<SurveyTaker__c> check = [SELECT Contact__c, Survey__c, Case__c, User__c From SurveyTaker__c Where Survey__c=:surveyId and
            ((Contact__c != null and Contact__c=:contactId) or (Case__c!= null and Case__c = :caseId)
            or (User__c!= null and User__c = :userId))];
            if(check != null && check.size()>0){
                Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.LABS_SF_You_have_already_taken_this_survey));

                return false;
            }
        }
COMMENT END */

For 2), In ADDITION TO above code,

CHANGE


st.Contact__c  = (contactId == null)?null: String.escapeSingleQuotes(contactId);
        st.Survey__c = surveyId;
        st.Taken__c = 'true';
        st.Case__c = (caseId == null)?null: String.escapeSingleQuotes(caseId);
        st.User__c = userId;

TO

st.Opportunity__c  = (opportunityId == null)?null: String.escapeSingleQuotes(opportunityId);
st.Contact__c  = (contactId == null)?null: String.escapeSingleQuotes(contactId);
        st.Survey__c = surveyId;
        st.Taken__c = 'true';
        st.Case__c = (caseId == null)?null: String.escapeSingleQuotes(caseId);
        st.User__c = userId;
Brisingr75 commented 3 years ago

Hi Jrattanpal,

Thank you for your answer it helps ! So the first point it seems to work. Regarding the point 2 I have a message error in my sandbox when I want to save it :

Error_apex_class_SF

Can you help me ?

Thanks Steve

jrattanpal commented 3 years ago

You need to define this variable around line#29

https://github.com/SalesforceLabs/survey-force/blob/master/force-app/main/default/classes/ViewSurveyController.cls

public String opportunityId {get;set;}
Brisingr75 commented 3 years ago

I have a still an error :

Error: Compile Error: Variable does not exist: Opportunity__c at line 397 column 12

jrattanpal commented 3 years ago

Did you create a custom look up field called Opportunity on Suvery Taker Object?

It can't seem to find it.

Brisingr75 commented 3 years ago

Indeed it's the issue, I created well in the Survey taken object (because I don't have survery taker object) and it's saved correctly. However when I fill a survey I can't share it with opportunity, I have only contact or case : https://salecycle--prodcopy--c.visualforce.com/apex/takesurvey?id=a1v3H000001M0HYQA0&cId={!Contact.Id}&caId={!Case.id}

Normally it should be : https://salecycle--prodcopy--c.visualforce.com/apex/takesurvey?id=a1v3H000001M0HYQA0&cId={!Contact.Id}&caId={!Case.id}&oId={!Opportunity.id} no ?

Many thanks for your help and your reactivity 👍

jrattanpal commented 3 years ago

Yes, that's how you provide OppID in URL. When they submit Survey, it should store that.

You don't need to share al, just share what you want them like

https://salecycle--prodcopy--c.visualforce.com/apex/takesurvey?id=a1v3H000001M0HYQA0&oId={!Opportunity.id}

Brisingr75 commented 3 years ago

Hi Jrattanpal,

I made many tests and it seems to not working :

URL : https://salecycle--prodcopy--c.visualforce.com/apex/takesurvey?id=a1v3H000001M0HYQA0&oId=0064J000006SVTvQAO

When I fill the survey I have this message image

In SF the lookup field seems not filled like expected : image

Any ideas ?

jrattanpal commented 3 years ago

"empty" is text string under Survey in Header tab. You can replace that with any text message to show that survey was sbumitted.

As for it t storing opportunity, I can't say without checking. I will need Apex logs to see what is going on. For that,

Brisingr75 commented 3 years ago

Got it for empty.

Regarding the logs and set a coekie, sorry I'm little lost, I don't understand what I need to do with your link. Can you more elaborate please ?

Regarding debug logs what information should I suppose to put in this screen ? : image

Thanks for your help

jrattanpal commented 3 years ago

You can select "New Debug Level" and set Apex to Finest.

For entity, you have to select the site user. It should show something like "YOUR_SITE site guest user" (or so)

In addition to this, for guest users, you have to set a cookie in browser. That link shows you how to set the cookie and the exact values it should have. I am not sure how I can guide you there to set that cookie for debug.

jrattanpal commented 3 years ago

Closing this issue. You can create a new issue if needed.