• Nidhi Sharma 17
  • NEWBIE
  • 60 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 12
    Replies

Hello everyone,

I want to display standard account object data onto vf page and then, on click of a button, export it in excel format. Kindly help.

Thank you.

I have a VF page in a custom object consisting of 2 Text Area Field viz. 'Choose' and 'Weights'

In 'Choose' Text Area, I enter options:
a
b
c
d


And in 'Weights' Text Area, I enter options:

1
2
3
4

I want to relate one weight to one option. Say a-1, b-2, c-3, d-4

The code to seperate each field be:
 

private List<SelectOption> stringToSelectOptions(String str){
    List<String> strList = str.split('\\r|\n');
    List<SelectOption> returnVal = new List<SelectOption>();
    for(String s: strList){
      returnVal.add(new SelectOption(s,s));
    }
    return returnVal;
But now I am unable to link it to the previous 'Choose' field and display in the record.
I have an action 'hello1' on an apex command button 'Cancel'. On clicking Cancel I want to navigate back to the particular Order record whose survey record I am capturing at present. URL of the current survey page is 
https://c.ap2.visual.force.com/apex/TakeSurvey?id=a0R28000000ChcAEAS&cId=801280000004CYc

VF Code
<apex:page standardcontroller="Survey__c" extensions="ViewSurveyController" cache="false" sidebar="false" showheader="false">
<apex:commandButton action="{!hello1}"  value="Cancel"/>
</apex:page>

Apex Class
public PageReference hello1() {
        orderId = Apexpages.currentPage().getParameters().get('cId');
        PageReference reference=new PageReference('https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId');
        reference.setRedirect(true);
        return reference; 
    }

But 
'https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId'
is not navigating me back to particular record, rather to the whole list of Order Records. Kindly help.
 
I have a VF page for a survey. I want an intermediate commit action so that the user can save the fields he entered till then and can resume from there itself. But on page refresh i am not able to hold values for that record. Whole of the page gets refreshed and the values previously entered gets flushed for that record.

VF Page
 
<apex:page standardcontroller="Survey__c" extensions="ViewSurveyController" cache="false" sidebar="false" showheader="false">
<style>
    <apex:outputText value="{!surveyContainerCss}" />
</style>

<div id="survey_container">   
    <apex:form id="theForm"   >
    <apex:outputPanel id="seeSurvey" rendered="{!thankYouRendered == false}" >
        <apex:outputField value="{!Survey__c.Survey_Header__c}"/>
        <h1><apex:outputField value="{!Survey__c.Name}" rendered="{!Survey__c.Hide_Survey_Name__c == false}" /></h1>
        
    </apex:outputPanel>
    <apex:pageMessages />
    <apex:pageBlock rendered="{!thankYouRendered == false}" > 
        <div id="qList">
            
            <apex:repeat value="{!allQuestions}" var="qPreview" id="aQPreview">
    
            <div id="{!qPreview.id}" >
        
                    <apex:pageBlock id="pblock"> 
                        <h1 class="question">
                            <span class="questionNumber">{!qPreview.orderNumber}</span>
                            {!qPreview.question}
                            <apex:outputPanel rendered="{!qPreview.required}" styleClass="requiredText">
                                ({!$Label.LABS_SF_Required})
                            </apex:outputPanel>
                        </h1>
                     <div id="radio"> 
                      <apex:selectRadio layout="pageDirection" rendered="{!qPreview.renderSelectRadio}" value="{!qPreview.selectedOption}" >
                        <apex:selectOptions value="{!qPreview.singleOptions}"/>
                      </apex:selectRadio>
                    </div>
                    <div id="checkbox">           
                      <apex:selectCheckboxes layout="pageDirection" rendered="{!qPreview.renderSelectCheckboxes}" value="{!qPreview.selectedOptions}" >
                        <apex:selectOptions value="{!qPreview.multiOptions}"/>
                      </apex:selectCheckboxes> 
                    </div>
                    <div id="text"> 
                       <apex:inputTextArea cols="50" rows="10" rendered="{!qPreview.renderFreeText}" value="{!qPreview.choices}"/>  
                    </div>
                    <div id="row">
                      <apex:selectRadio rendered="{!qPreview.renderSelectRow}" value="{!qPreview.selectedOption}">
                        <apex:selectOptions value="{!qPreview.rowOptions}"/>
                      </apex:selectRadio>
                    </div>            
     
                    </apex:pageBlock>   
              
            </div>  <!-- qPreview.id -->
            
            </apex:repeat>
                         
        </div> <!-- qList -->
        
            
    </apex:pageBlock>
        <apex:outputPanel rendered="{!thankYouRendered == false}">
        <apex:outputPanel rendered="{!isInternal}" >
            {!$Label.LABS_SF_Answer_as}: 
            <apex:selectRadio value="{!anonymousAnswer}">
                <apex:selectOptions value="{!anonymousOrUser}" />
                <apex:actionSupport event="onchange" rerender="hiddenAnonymousAnswer"/>
            </apex:selectRadio>
            <apex:inputHidden value="{!anonymousAnswer}" id="hiddenAnonymousAnswer"/>
            <BR />
        </apex:outputPanel>
        <apex:commandButton action="{!submitResults}" value="{!$Label.LABS_SF_SubmitSurvey}" rerender="theForm,seeSurvey" />
        
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:commandButton action="{!submit}" value="Commit"/> <!-- New button that i want to have on page -->
        
        
    </apex:outputPanel>
        <apex:outputPanel rendered="{!thankYouRendered == true}">
   
       <apex:outputText value="{!surveyThankYouText}"  escape="false"  />

        </apex:outputPanel>  
    </apex:form>

</div>
</apex:page>

Apex class
 
public void submitResults()
    {
        List <SurveyQuestionResponse__c> sqrList = new List<SurveyQuestionResponse__c>();
        
        for (question q : allQuestions)
        {
            SurveyQuestionResponse__c sqr = new SurveyQuestionResponse__c();
            if (q.renderSelectRadio == 'true')
            {
                
                if (q.required &&  (q.selectedOption == null || q.selectedOption == ''))
                {
                    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
                    return;
                }
                
                if (q.selectedOption == null || q.selectedOption == '')
                {
                    sqr.Response__c = '';
                }
                else
                {
                    sqr.Response__c = q.singleOptions.get(Integer.valueOf(q.selectedOption)).getLabel();
                }
                sqr.Survey_Question__c = q.Id;
                sqrList.add(sqr);
            }
            else if (q.renderFreeText == 'true')
            {
                if (q.required && q.choices == '')
                {
                    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
                    return;
                }
                System.debug('*****Select Radio ' + q.choices);
                
                sqr.Response__c = q.choices;
                sqr.Survey_Question__c = q.Id;
                sqrList.add(sqr);
            }
            else if (q.renderSelectCheckboxes == 'true')
            {
                if (q.required && (q.selectedOptions == null || q.selectedOptions.size() == 0))
                {
                    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
                    return;
                }
                
                for (String opt : q.selectedOptions)
                {
                    sqr = new SurveyQuestionResponse__c();
                    if (opt == '' || opt == null)
                    {
                        sqr.Response__c = '';
                    }               
                    else
                    {   
                        sqr.Response__c = q.multiOptions.get(Integer.valueOf(opt)).getLabel();
                    }
                    sqr.Survey_Question__c = q.Id;
                    sqrList.add(sqr);
                }
            }
            else if (q.renderSelectRow == 'true')
            {
                if (q.required && (q.selectedOption == null || q.selectedOption == ''))
                {
                    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out all required fields'));
                    return;
                }
                
                if (q.selectedOption == null || q.selectedOption == '')
                {
                    sqr.Response__c = '';
                }
                else
                {
                    sqr.Response__c = q.rowOptions.get(Integer.valueOf(q.selectedOption)).getLabel();
                }
                sqr.Survey_Question__c = q.Id;
                sqrList.add(sqr);
            }
            
             
        }
        if(AddSurveyTaker())
        {
            for (SurveyQuestionResponse__c sqr : sqrList)
            {
                sqr.SurveyTaker__c = surveyTakerId;
            }
            insert sqrList;
            thankYouRendered=true;      
        }

        
    }
    
    
    private Boolean AddSurveyTaker()
    {
        String userId;
        
        if (surveyId == null)
        {
            return false;
        }
        if(caseId.toUpperCase() =='NONE'|| caseId.length()<5)
          caseId = null;    
        if(contactId.toUpperCase() =='NONE'|| contactId.length()<5)
          contactId = null;         
        if (anonymousAnswer != 'Anonymous')
        {
            userId = UserInfo.getUserId();
        }
        else
        {
            userId = null;
        }
        
        if(anonymousAnswer != 'Anonymous' && (contactId != null || caseId != null))
        {
            List<SurveyTaker__c> check = [Select Contact__c, Survey__c, Case__c, User__c From SurveyTaker__c Where Contact__c=:contactId and Survey__c=:surveyId and Case__c = :caseId 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;       
            }
        }
        
     
        
        SurveyTaker__c st = new SurveyTaker__c();
        st.Order__c= OrderId;
        st.Survey__c = surveyId;
        st.User__c = userId;
        insert st;  
        surveyTakerId = st.Id;
        return true;    
    }
}

Kindly help.
I have an Apex Class to send an Email to someone as a Contact.
I want to send the 'Email' and the 'FirstName' fields of a particular Contact associated to a Task as parameters to the Apex Class when I click the Custom Button - 'Send' on the task detail page, so that I can send the email from the Apex Class using these field values.

My Apex Class : 
 
global class TestMailClass
{
    WebService static Integer TestMailMethod(String emailAddress, String fname1)
    {
          // Create a new Email
          
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 
      String[] toAddresses = new String[] {emailAddress};
      mail.setToAddresses(toAddresses);
    
      // Set who the email is sent from
      mail.setReplyTo('myemail@abc.com');
      mail.setSenderDisplayName('ABC');
    
      // Set email contents - used variables!
      mail.setSubject('TEST EMAIL');
      String body = 'Dear ' + fname1 + ', ';
      body += 'This is a sample mail that I am trying for the first time.';
      body += 'I write to send a random email ';
      mail.setHtmlBody(body);
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    
    return 0;

    }

}

My Custom Buttom in Task :
 
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var cntct = new sforce.SObject("Contact");

cntct.Id = "{!Contact.Id}";

var eid = new String(cntct.Email);
var fname = new String(cntct.FirstName);

var result = sforce.apex.execute("TestMailClass", "TestMailMethod",{emailAddress:eid, fname1:fname});

The problem here is the variables 'eid' and 'fname' remains undefined and is not passing into the Apex Class.
Need some help on this. Hope I made the question clear.

The one solution which worked for me was..

"Create a lookup field on the child
Create a unique field on the child, and hide this field from all page-layouts
Write a workflow, for any change of the lookup field, to copy that value from the lookup field into the unique field

This process has many overheads:
Extra field is required
Unique criteria is utilized (we only get 3 unique fields per object)
Workflow is used"


The only problem is the error message that gets displayed whenever the rule gets broken is out of line because it still refers to the hidden field which seems absurd.

Is there any way to change the pre-defined error message??

PS: I am looking for a one to one relationship between standard object (Users) and a custom object.

I have a custom object named 'Applications' and i want to have a related list of 'salesforce users' (That come under Setup -> Manage Users -> Users) on the detail page of applications. Is there any way of doing it?

Regards,
Nidhi

Hi,

I have a custom picklist created using visualforce page and apex. And its working very well in the visualforce page created. Now i wish to integrate it with my project in one of the custom object (Applications). This picklist will serve as a normal picklist there along with other fields already present there to take the input and save the record.

Please help.


Regards,

Nidhi

Is there a possible way to create a related list and save a record, say an 'employee' record through a custom button (Add an Employee) on 'employee related list' so that the record gets saved directly in the related list and not in any object.

PS: There is no custom object for employee. Just need to display the saved record in related list.


Thanks

In Applications (custom object), I have to create a custom picklist whose values should be various record types created for Applications. And if any record type is deleted, it gets reflected in the picklist values.
Please help.

I have two standard objects, Order and Contact. I have created a Contact lookup (API- Contact_Lookup__c) in Order and included its related  list in the page layout of Contact.

But when I enter a new record in Contact, then go to related list to add an order to it, hit save, the new Order record gets inserted in the Order records but it does not get displayed in the related list on contact detail page for that record.

Please help

I have a VF page in a custom object consisting of 2 Text Area Field viz. 'Choose' and 'Weights'

In 'Choose' Text Area, I enter options:
a
b
c
d


And in 'Weights' Text Area, I enter options:

1
2
3
4

I want to relate one weight to one option. Say a-1, b-2, c-3, d-4

The code to seperate each field be:
 

private List<SelectOption> stringToSelectOptions(String str){
    List<String> strList = str.split('\\r|\n');
    List<SelectOption> returnVal = new List<SelectOption>();
    for(String s: strList){
      returnVal.add(new SelectOption(s,s));
    }
    return returnVal;
But now I am unable to link it to the previous 'Choose' field and display in the record.
I have an action 'hello1' on an apex command button 'Cancel'. On clicking Cancel I want to navigate back to the particular Order record whose survey record I am capturing at present. URL of the current survey page is 
https://c.ap2.visual.force.com/apex/TakeSurvey?id=a0R28000000ChcAEAS&cId=801280000004CYc

VF Code
<apex:page standardcontroller="Survey__c" extensions="ViewSurveyController" cache="false" sidebar="false" showheader="false">
<apex:commandButton action="{!hello1}"  value="Cancel"/>
</apex:page>

Apex Class
public PageReference hello1() {
        orderId = Apexpages.currentPage().getParameters().get('cId');
        PageReference reference=new PageReference('https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId');
        reference.setRedirect(true);
        return reference; 
    }

But 
'https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId'
is not navigating me back to particular record, rather to the whole list of Order Records. Kindly help.
 
I have an Apex Class to send an Email to someone as a Contact.
I want to send the 'Email' and the 'FirstName' fields of a particular Contact associated to a Task as parameters to the Apex Class when I click the Custom Button - 'Send' on the task detail page, so that I can send the email from the Apex Class using these field values.

My Apex Class : 
 
global class TestMailClass
{
    WebService static Integer TestMailMethod(String emailAddress, String fname1)
    {
          // Create a new Email
          
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 
      String[] toAddresses = new String[] {emailAddress};
      mail.setToAddresses(toAddresses);
    
      // Set who the email is sent from
      mail.setReplyTo('myemail@abc.com');
      mail.setSenderDisplayName('ABC');
    
      // Set email contents - used variables!
      mail.setSubject('TEST EMAIL');
      String body = 'Dear ' + fname1 + ', ';
      body += 'This is a sample mail that I am trying for the first time.';
      body += 'I write to send a random email ';
      mail.setHtmlBody(body);
    
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    
    return 0;

    }

}

My Custom Buttom in Task :
 
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var cntct = new sforce.SObject("Contact");

cntct.Id = "{!Contact.Id}";

var eid = new String(cntct.Email);
var fname = new String(cntct.FirstName);

var result = sforce.apex.execute("TestMailClass", "TestMailMethod",{emailAddress:eid, fname1:fname});

The problem here is the variables 'eid' and 'fname' remains undefined and is not passing into the Apex Class.
Need some help on this. Hope I made the question clear.

The one solution which worked for me was..

"Create a lookup field on the child
Create a unique field on the child, and hide this field from all page-layouts
Write a workflow, for any change of the lookup field, to copy that value from the lookup field into the unique field

This process has many overheads:
Extra field is required
Unique criteria is utilized (we only get 3 unique fields per object)
Workflow is used"


The only problem is the error message that gets displayed whenever the rule gets broken is out of line because it still refers to the hidden field which seems absurd.

Is there any way to change the pre-defined error message??

PS: I am looking for a one to one relationship between standard object (Users) and a custom object.

I have a custom object named 'Applications' and i want to have a related list of 'salesforce users' (That come under Setup -> Manage Users -> Users) on the detail page of applications. Is there any way of doing it?

Regards,
Nidhi

Hi,

I have a custom picklist created using visualforce page and apex. And its working very well in the visualforce page created. Now i wish to integrate it with my project in one of the custom object (Applications). This picklist will serve as a normal picklist there along with other fields already present there to take the input and save the record.

Please help.


Regards,

Nidhi

Is there a possible way to create a related list and save a record, say an 'employee' record through a custom button (Add an Employee) on 'employee related list' so that the record gets saved directly in the related list and not in any object.

PS: There is no custom object for employee. Just need to display the saved record in related list.


Thanks

In Applications (custom object), I have to create a custom picklist whose values should be various record types created for Applications. And if any record type is deleted, it gets reflected in the picklist values.
Please help.

I have two standard objects, Order and Contact. I have created a Contact lookup (API- Contact_Lookup__c) in Order and included its related  list in the page layout of Contact.

But when I enter a new record in Contact, then go to related list to add an order to it, hit save, the new Order record gets inserted in the Order records but it does not get displayed in the related list on contact detail page for that record.

Please help