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
LoneStar69LoneStar69 

How to grab parent ID while inserting child records

Guys, we have a survey page built from visualforce hosted on a force.com site that allows users to submit surveys, survey URL is included as a link in the final response template which is sent out on case closure.
In Salesforce, i created master-detail between Case and Survey object. Now my question is how to relate the submitted surveys to the case? Is this possible?
Best Answer chosen by LoneStar69
Jainam ContractorJainam Contractor
Hi,

It is definitely possible to relate the Survey with the Case. In the VF link which you will send at the Case closure, in that VF link at the end embed the CaseId and handle the same in the Controller/ VF page.

something like: VF_page_link/caId=(CaseId).

There is a free survey app named SurveyForce provided by the Salesforce Labs. It has inbuilt feature to relate the Survey with the Case and Contact. You can have a look at it and check if it suits your need.

Let me know if you need more assistance.

Thanks,
Jainam Contractor

All Answers

Jainam ContractorJainam Contractor
Hi,

It is definitely possible to relate the Survey with the Case. In the VF link which you will send at the Case closure, in that VF link at the end embed the CaseId and handle the same in the Controller/ VF page.

something like: VF_page_link/caId=(CaseId).

There is a free survey app named SurveyForce provided by the Salesforce Labs. It has inbuilt feature to relate the Survey with the Case and Contact. You can have a look at it and check if it suits your need.

Let me know if you need more assistance.

Thanks,
Jainam Contractor
This was selected as the best answer
LoneStar69LoneStar69
Hi Jainam, can you please expand on the caseId approach?
Right now the hyperlink from the template is - https://xxxxx-xxxxx.cs33.force.com/Survey
Below is the controller code -
public with sharing class Survey {

public Survey__c s {
        get{
            if(s == null)
                s = new Survey__c();
            return s;
        }
        set;
    }
    
    public Survey(){}
    
public PageReference submit() {
    
        try{
        insert s;
        }
        catch(exception e){}
        return (new pagereference('/apex/thanks').setredirect(true));
}
    public PageReference cancel() {
        return (new pagereference('/apex/thanks').setredirect(true));
}}
i am not sure to how to grab the Case Id onto the above controller, thanks for your help!
Jainam ContractorJainam Contractor
Hi,

You can create a lookup relation between the Survey and Case object. Using SOQL, get the Case Id to which you want to relate the Survey and then on the Child relationship field say Case__c assign that Case Id and rest logic remains same. i.e insert the Survey record and the case will be associated with the Survey.

Please try this and let me know if it works.

Let me know if you need more assistance. Mark it as the solution if it solved your purpose.

Thanks,
Jainam Contractor,
Salesforce Consultant,
Varasi LLC
www.varasi.com
LoneStar69LoneStar69
Hi, i am still missing something here, I created a relationship field, but not sure on how to grab the Case Id here from the site page because surveys are submitted via a force.com site which is https://xxxxx-xxxxx.cs33.force.com/Survey, can you help me with the SOQL?