function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Force.com Sites Survey Form, URL not working as expected pelase help!

Hey there,

I have a site which is used to automatically send a link to a client at certain times and then once submitted automatically attach to the clients account. This all works fine, I am just having one problem with attaching it to another custom object called "office__c".


This is the url that is sent in the automatic email. http://destinyliveoffice.force.com/DestinySurvey?acct={!Account.Id}&Off={!Account.OfficeId__c}&Sur=120DAIPC

However, upon clicking the url....the account ID is filled with the correct ID, however the officeID for some reason will show the office name.
E.G. http://destinyliveoffice.force.com/DestinySurvey?acct={!Account.Id}&Off=Sydney&Sur=120DAIPC

This is preventing the survey upon being submitted from being added to both the account and the office. What could be causing this? please help?

My class and VF page are as below:

 

public class extDestinySurvey
{
    public Destiny_Survey__c Dess {get;set;}

    private Id AccountId
    {
        get
        {
            if ( AccountId == null )
            {
                String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
                try
                {
                    if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
                }
                catch ( Exception e ) {}
            }
            return AccountId;
        }
        private set;
    }
    
    Private Id OfficeId
    {
        get
        {
            if ( OfficeId == null )
            {
                String OffParam = ApexPages.currentPage().getParameters().get( 'Off' );
                try
                {
                    if ( !String.isBlank( OffParam ) ) OfficeId = Id.valueOf( OffParam );
                }
                catch ( Exception e ) {}
            }
            return OfficeId;
        }
        Private set;
    }
    
 


    
    public extDestinySurvey(ApexPages.StandardController controller)
    {
        Dess = (Destiny_Survey__c)controller.getRecord();
         Dess = (Destiny_Survey__c) controller.getRecord();
        Dess.Survey_Code__c = ApexPages.currentPage().getParameters().get('Sur');
    }

    public PageReference saveDestinySurvey()
    {
        Dess.Account__c = AccountId;
        Dess.Office__c = OfficeId;

        
        upsert Dess;
      

        // Send the user to the detail page for the new account.
        return new PageReference('/apex/Destiny_Survey_Thank_You');
    }
}
and

<apex:page standardController="Destiny_Survey__c" extensions="extDestinySurvey" showHeader="false" >

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script src="{!URLFOR($Resource.charCounter)}" type="text/javascript"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $('.countable1').jqEasyCounter({
          'maxChars': 250,
          'maxCharsWarning': 40,
          'msgFontSize': '12px',
          'msgFontColor': '#000',
          'msgFontFamily': 'Verdana',
          'msgTextAlign': 'left',
          'msgWarningColor': '#F00',
          'msgAppendMethod': 'insertAfter'               
        });
      });
    </script>
    <style type="text/css">
      body {
        font-family: "Arial", "Helvetica", "Verdana", "Sans-Serif";
        margin: 0px;
        padding: 12px;
      }
      img {
        border: 0px none #ffffff;
        margin: 0px;
        padding: 0px;
      }
      [id*=SurveyTitle] {
        font-size: 24px;
      }
      [id*=ProductServiceSection] {
        font-size: 12px;
      }
      [id*=FeedbackSection] {
        font-size: 12px;
      }
      [id*=Buttons] {
        font-size: 12px;
      }
    </style>
  </head>

  <img alt="" src="{!$Resource.Destiny_Logo}" />
  <br />
  <br />
  <apex:form id="myForm">
    <apex:pageBlock id="SurveyTitle" title="Destiny Survey" mode="edit">
      

      <apex:pageBlockSection id="FeedbackSection" title="Feedback" columns="1">
        <apex:InputField id="Rating" label="Out of 10 how likely are you to refer Destiny to a friend or colleague?"  value="{!Destiny_Survey__c.How_likely_are_you_to_refer_Destiny__c}" />
        <apex:pageBlockSectionItem >
          <apex:outputlabel value="" />
            <c:flexslidercomponent minSliderValue="0" maxSliderValue="10"
              startSliderValue="{!Destiny_Survey__c.How_likely_are_you_to_refer_Destiny__c}"
              boundDomId="{!$Component.FeedbackSection.Rating}"
              width="180" />
        </apex:pageBlockSectionItem>
        <apex:inputTextarea id="Explanation" label="Please explain why you gave your rating." StyleClass="countable1" value="{!Destiny_Survey__c.Explain_why_you_gave_your_rating__c}" rows="5" cols="100"/>
      </apex:pageBlockSection>

      <apex:pageBlockButtons id="Buttons" location="bottom">
        <apex:commandButton value="Submit" action="{!saveDestinySurvey}"/>
      </apex:pageBlockButtons>
    </apex:pageBlock>

  </apex:form>
</apex:page>


 

Best Answer chosen by Developer.mikie.Apex.Student
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
I think I found my issue.....I had it as a hyperlink..Rather than editing the entire hyperlink, I was just edditing it how it appeared on the email template. This leads me to believe that i was just changing what it said and not where the link led. Everything works now, thank you for your help. :)

All Answers

Kiran RKiran R
Hello,

Please see this post about id.ValueOf(). This doesn't seems to be a supported by sf from APIv29 onwards. 

https://developer.salesforce.com/forums/?id=906F0000000929ZIAQ
Sumitkumar_ShingaviSumitkumar_Shingavi
Do
OfficeId = (Id) OffParam;
instead of
OfficeId = Id.valueOf( OffParam );
Also while forming URL "http://destinyliveoffice.force.com/DestinySurvey?acct={!Account.Id}&Off={!Account.OfficeId__c}&Sur=120DAIPC"
Can you try below:
http://destinyliveoffice.force.com/DestinySurvey?acct={!Account.Id}&Off={!Account.OfficeId__r.Id}&Sur=120DAIPC
I am assuming that "OfficeId__c" is a lookup field.

PS: if this answers your question then hit Like and mark it as solution!
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey, i tried your solution and it does not work still. The weird thing is that the Account Lookup works, but even if the office ID appears in the URL of the email...upon clicking, it will either state the office name or nothing. What could be causing this? Thank you for your help
Sumitkumar_ShingaviSumitkumar_Shingavi
Can you help me with below questions:
1. Where you forming this link? In a Custom button?
2. Did you made sure that data type of OfficeId__c is "Lookup" or "Master-Detail"
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey there, I am forming this link in an automatic email hyperlink. It appears in the email looking like this: http://destinyliveoffice.force.com/DestinySurvey?acct=00194300014nV7v&Off=a0O9000000DVCKG&Sur=120DAIPC . But then after clicking, the letters and numbers after Off, they just disappear. Yes, it is a lookup. Should i make it master-detail? Thank you for your time
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
I just thought I might add, that the actual lookup is office__c....but, it said that I should enter it as officeid__c when adding the merge fields.
Sumitkumar_ShingaviSumitkumar_Shingavi
1 You should enter API name in merge field so it if is "Office__c" then merge field will look like "{!Objectname.Office__c}"
2. Can you change parameter name from "Off" to "OffId" in URL. I am not sure if browser treating your "Off" as something different if it is keywork for it. After this change, make sure you do correspoding changes in Controller of DestinySurvey VF page to aquire "OffId" rather than "Off".
3. No need to change from Lookup to Master-Detail as it will not impact on what you facing.
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey there,

thank you for all your help firstly. I have tried your suggestions and the url is back to rendering as offID=Melbourne (rather than, offId=0980958094). I am not sure what I am doing wrong, why would accountId work and not office id. This is my class and URL.

public class extDestinySurvey
{
    public Destiny_Survey__c Dess {get;set;}

    private Id AccountId
    {
        get
        {
            if ( AccountId == null )
            {
                String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
                try
                {
                    if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
                }
                catch ( Exception e ) {}
            }
            return AccountId;
        }
        private set;
    }
    
    Private Id OfficeId
    {
        get
        {
            if ( OfficeId == null )
            {
                String OffParam = ApexPages.currentPage().getParameters().get( 'OffId' );
                try
                {
                    if ( !String.isBlank( OffParam ) ) OfficeId = (Id) OffParam;
                }
                catch ( Exception e ) {}
            }
            return OfficeId;
        }
        Private set;
    }
    
 


    
    public extDestinySurvey(ApexPages.StandardController controller)
    {
        Dess = (Destiny_Survey__c)controller.getRecord();
         Dess = (Destiny_Survey__c) controller.getRecord();
        Dess.Survey_Code__c = ApexPages.currentPage().getParameters().get('Sur');
    }

    public PageReference saveDestinySurvey()
    {
        Dess.Account__c = AccountId;
        Dess.Office__c = OfficeId;

        
        upsert Dess;
      

        // Send the user to the detail page for the new account.
        return new PageReference('/apex/Destiny_Survey_Thank_You');
    }
}

and URL

http://destinyliveoffice.force.com/DestinySurvey?acct={!Account.Id}&OffId={!Account.Office__c}&Sur=120DAIPC
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
I think I found my issue.....I had it as a hyperlink..Rather than editing the entire hyperlink, I was just edditing it how it appeared on the email template. This leads me to believe that i was just changing what it said and not where the link led. Everything works now, thank you for your help. :)
This was selected as the best answer