• deano
  • NEWBIE
  • 25 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies

Hi all.

 

I'm quite new to salesforce.

 

I have an inputText tag on a custom component that has it's value set to a property on the controller. Yeasterday this was working fine but today it seems that the controllers and views are not wired up and so the property is always empty, regardless of what the user puts in the input box.

 

My VF page lists multiple of these components in a dataList, and to each of these components I pass as an attribute the parent VF page. The parents VF page controller has a collection that contains the components that are listed on the page.

 

I then have a method on each of the components that returns the text that is supposed to be in the property on the component controller.

 

That was supposed to allow me to call an action method from the page and in that method loop through the components on the page and retrieve the text in the components input box.

 

Again that was working yesterday but not today. Something else that might shed some light is that the commandButton on the page was also not calling the method assigned to its action attribute.

 

VF Page

 

 

<apex:page sidebar="false" showHeader="false" controller="questionsController">

<apex:form >

<apex:outputText value="{!SurveyResponse.Account_Survey__r.Survey__r.Name}" /> <apex:dataList value="{!Questions}" var="Question" id="dlQuestions">

<apex:outputText value="{!Question.Name}" />

<c:QuestionOptions Question="{!Question}" PageController="{!This}" />

</apex:dataList>

<apex:commandLink action="{!SubmitResponse}" value="Submit" id="btnSubmit" immediate="true" /> <apex:messages />

</apex:form>

</apex:page>

 

 Page Controller

 

public class questionsController {

private List<comp_QuestionOptionsController> questionOptionsControllers;

public void AddQuestionOptionsController(comp_QuestionOptionsController controller){

Boolean exists = false;

for(comp_QuestionOptionsController existing: questionOptionsControllers){

if(existing == controller){

exists = true;

break;

}

}

if(!exists)

questionOptionsControllers.add(controller);

}

 

public questionsController getThis(){

return this;

}

 

public Survey_Response__c surveyResponse{get; private set;}

 

public Id optionsId{get;set;}

 

public questionsController(){

String responseId = ApexPages.currentPage().getParameters().get('id');

questionOptionsControllers = new List<comp_QuestionOptionsController>();

SurveyResponse = [

SELECT Id, Account_Survey__r.Survey__r.Id, Account_Survey__r.Survey__r.Name

FROM Survey_Response__c

WHERE Id = :responseId

];

}

 

public List<Question__c> getQuestions(){

List<Question__c> questions = [

SELECT Name,Response_Type__c,

(

SELECT Id, Name

FROM Options__r

)

FROM Question__c

WHERE Survey__c = :surveyResponse.Account_Survey__r.Survey__r.Id

];

return questions;

}

 

public PageReference SubmitResponse(){

List<Answer__c> answers = new List<Answer__c>();

try{

for(comp_QuestionOptionsController controller:questionOptionsControllers){

answers.add(new Answer__c(

Question__c = controller.MyQuestion.Name,

Answer__c = controller.getAnswer(),

Rating__c = 'Excellent',

Survey_Response__c = surveyResponse.Id

));

}

insert answers;

}catch(DmlException ex){ApexPages.addMessages(ex);}

return null;

}

 

}

 

 VF Component

 

<apex:component controller="comp_QuestionOptionsController">

<apex:attribute name="PageController" type="questionsController" assignTo="{!MyPage}" required="true" description="The controller for the page." />

<apex:attribute name="Question" description="The parent Question" type="Question__c" required="true" assignTo="{!MyQuestion}" />

 

<apex:selectList rendered="{!DropDownListVisible}" size="1" multiselect="false" value="{!SelectedItems}" > <apex:selectOptions value="{!Items}" />

</apex:selectList>

 

<apex:inputText rendered="{!TextOrNumberOrDateVisible}" value="{!TextValue}" />

 

<apex:selectCheckboxes rendered="{!CheckBoxesVisible}" value="{!SelectedItems}">

<apex:selectOptions value="{!Items}" />

</apex:selectCheckboxes>

 

<apex:selectRadio rendered="{!RadioButtonsVisible}" value="{!SelectedItems}">

<apex:selectOptions value="{!Items}" />

</apex:selectRadio>

</apex:component>

 

 

 

 

 Component Controller

 

public class comp_QuestionOptionsController{

public questionsController MyPage{

get;

set{

((questionsController)value).AddQuestionOptionsController(this);

}

}

 

public Question__c MyQuestion{get;set;}

 

public Boolean DropDownListVisible{

get{

return MyQuestion.Response_Type__c == 'Drop Down List';

}

}

 

public Boolean TextOrNumberOrDateVisible{

get{

return MyQuestion.Response_Type__c == 'Number' || MyQuestion.Response_Type__c == 'Free Text' || MyQuestion.Response_Type__c == 'Date';

}

}

 

public Boolean CheckBoxesVisible{

get{

return MyQuestion.Response_Type__c == 'Check Boxes';

}

}

 

public Boolean RadioButtonsVisible{

get{

return MyQuestion.Response_Type__c == 'Radio Button List';

}

}

 

public String TextValue{get;set;}

 

public String[] SelectedItems{get;set;}

 

public List<SelectOption> getItems(){

List<SelectOption> items = new List<SelectOption>();

for(Option__c option:MyQuestion.Options__r){

items.add(new SelectOption(option.Id,option.Name));

}

return items;

}

 

public String getAnswer(){

String answer = '';

if(DropDownListVisible || CheckBoxesVisible || RadioButtonsVisible){

//for(Integer i=0;i<SelectedItems.size() - 1; i++){

//answer = answer + SelectedItems[i] + ', ';

//}

answer = 'multi';

}

 

if(TextOrNumberOrDateVisible){

//answer = 'text';

answer = TextValue;

}

 

//if(answer.endsWith(', '))

//answer = answer.substring(0, answer.lastIndexOf(' ') - 1);

//if(answer == '')

//answer = 'answer was empty';

 

return answer;

}

}

 

 I don't get any errors with this. It is just that the "TextValue" property on the component controller is always empty.

 

Any help would be greatly appreciated, I'm pulling my hair out over this one!

 

Thanks 

 

 

 

Message Edited by deano on 02-03-2010 02:59 PM
  • February 03, 2010
  • Like
  • 0

Hello, i'm new to salesforce/apex/soql, so any help would be muchly appreciated!

 

Scenario:

A custom object Program__c has  child events which represent program sessions. The program also has children of another custom object Participant__c that represents participants of the program. Participant__c is a junction object that looks up to the program and a contact.

 

I need to select out all events that are occuring in 3 days, and send out an email to all participants of the events program reminding them the event is up coming.

 

The only solution I could work out for this was to use cronkit (appexchange app) to poll for all relevent events at least daily, and in the cronkit trigger send emails using apex to the participants of the event.

 

I have all of this working. With the following code (I've left out irrelevent parts) which resides inside a cronkit trigger:

 

DateTime nowPlusThreeDays = Datetime.newInstance(Datetime.now().date(), Datetime.now().time()).addDays(3);

 

List<Event> events = [
     SELECT e.Description, e.Id, e.Location, e.WhatId, e.Subject, e.IsAllDayEvent, e.ActivityDateTime, e.EndDateTime, What.Id
     FROM Event e
     WHERE
      e.ActivityDateTime >= :dateTime.newInstance(nowPlusThreeDays.Year(),nowPlusThreeDays.month(),nowPlusThreeDays.day()) AND
      e.ActivityDateTime < :dateTime.newInstance(nowPlusThreeDays.date().Year(),nowPlusThreeDays.month(),nowPlusThreeDays.day(),23,59,59) AND
      e.RecordType.Name = 'Program Session' AND
      e.Participant_Reminder_Email_Sent__c = False
     LIMIT 100
    ];

 

EmailTemplate template = [SELECT ID FROM EmailTemplate WHERE (name = 'Program Participant Reminder') LIMIT 1];

 

for(Event event:events){

 

Program__c program = [SELECT Id, Name, (SELECT Participant__r.Name, Participant__r.Id FROM Junction_Objects__r) FROM Program__c WHERE Id = :event.WhatId LIMIT 1];

 

for(Junction_Object__c junction:program.Junction_Objects__r){
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      mail.setTemplateId(template.Id);
      mail.setTargetObjectId(junction.Participant__r.Id);
     

emails.add(mail);
     }
     
     Messaging.sendEmail(emails);
     
     event.Participant_Reminder_Email_Sent__c = True;
     update event;
    }

 

The problem is I really need to get the second query (the one where I get the program info and the child junction objects) out of the for loop iterating through the selected events.

 

Cronkit has a limit of 20 soql queries, and it doesn't look very good anyway.

 

Could anyone please help me to modify my data queries so that they are not inside any loops. I tried but always got an error about the first sobject returned by a sub select being a child of the outer select. I understand that, but don't know how to get around the fact that I must first go up to the program and then down to the participants.

 

Thank you very much for any help!!!

 

Deano

  • November 23, 2009
  • Like
  • 0

Hello everyone,

 

This is my first post here, I have web development background in the .net space and am diving into SFDC, apex and VF.

 

There are a few things i'm struggling with as I haven't done any of that before.

 

I have built a trigger that is supposed to fire on insert and update of lead records. I'm in a sandbox environment. I have written tests for all methods involved and have 100% coverage on all.

 

If I browse to my sandbox instance and insert or update leads the trigger performs the tasks that it should.

 

However, when running the tests it fails with the error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

 

If I remove the "before update" from the trigger signiture everything runs without a problem. Adding back in "before update" and the problem arises.

 

I'll past the code below. Countries is a class that contains static methods that return List<String>

 

 trigger SetNotification on Lead (after insert, after update) {

// dean@sqwarepeg.com

//This trigger checks if any of the selections in the source or destination countries multi picklists require investigation

//Countries require further investigation depending on what list they appear in in the Countries static methods

String errorMessage = 'Some of the selected countries are possibly not eligible';

Id businessClientRTId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Business Clients').getRecordTypeId();

Id privateClientRTId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Private Clients').getRecordTypeId();

for(Lead lead:trigger.new){

 

List<String> compareCountries = new List<String>();

if(lead.RecordTypeId == businessClientRTId){

compareCountries = Countries.GetCorporatePossiblyEligible();

compareCountries.addAll(Countries.GetCorporateNonEligible());

}else if(lead.RecordTypeId == privateClientRTId){

compareCountries = Countries.GetPrivatePossiblyEligible();

compareCountries.addAll(Countries.GetPrivateNonEligible());

}

List<String> selectedCountries = new List<String>();

//Source Country Check

String strCountries = String.valueOf(lead.Source_Country_s_A_L__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

strCountries = String.valueOf(lead.Source_Country_s_M_Z__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

Boolean matchFound = false;

for(String selectedCountry:selectedCountries)

{

for(String compareToCountry:compareCountries){

if(selectedCountry == compareToCountry){

matchFound = true;

break;

}

}

if(matchFound)

break;

}

if(matchFound)

lead.Source_Country_Notification__c = errorMessage.toUpperCase();

else

lead.Source_Country_Notification__c = '';

//Destination Country Check

selectedCountries.clear();

strCountries = String.valueOf(lead.Destination_Country_s_A_L__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

strCountries = String.valueOf(lead.Destination_Country_s_M_Z__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

matchFound = false;

for(String selectedCountry:selectedCountries)

{

for(String compareToCountry:compareCountries){

if(selectedCountry == compareToCountry){

matchFound = true;

break;

}

}

if(matchFound)

break;

}

if(matchFound)

lead.Destination_Country_Notification__c = errorMessage.toUpperCase();

else

lead.Destination_Country_Notification__c = '';

}

}

 

What is the issue with before update? I want the same functionality regardless of insert or update. 

 

Thank you for any assistance!!! 

  • October 20, 2009
  • Like
  • 0

Hello everyone,

 

This is my first post here, I have web development background in the .net space and am diving into SFDC, apex and VF.

 

There are a few things i'm struggling with as I haven't done any of that before.

 

I have built a trigger that is supposed to fire on insert and update of lead records. I'm in a sandbox environment. I have written tests for all methods involved and have 100% coverage on all.

 

If I browse to my sandbox instance and insert or update leads the trigger performs the tasks that it should.

 

However, when running the tests it fails with the error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

 

If I remove the "before update" from the trigger signiture everything runs without a problem. Adding back in "before update" and the problem arises.

 

I'll past the code below. Countries is a class that contains static methods that return List<String>

 

 trigger SetNotification on Lead (after insert, after update) {

// dean@sqwarepeg.com

//This trigger checks if any of the selections in the source or destination countries multi picklists require investigation

//Countries require further investigation depending on what list they appear in in the Countries static methods

String errorMessage = 'Some of the selected countries are possibly not eligible';

Id businessClientRTId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Business Clients').getRecordTypeId();

Id privateClientRTId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Private Clients').getRecordTypeId();

for(Lead lead:trigger.new){

 

List<String> compareCountries = new List<String>();

if(lead.RecordTypeId == businessClientRTId){

compareCountries = Countries.GetCorporatePossiblyEligible();

compareCountries.addAll(Countries.GetCorporateNonEligible());

}else if(lead.RecordTypeId == privateClientRTId){

compareCountries = Countries.GetPrivatePossiblyEligible();

compareCountries.addAll(Countries.GetPrivateNonEligible());

}

List<String> selectedCountries = new List<String>();

//Source Country Check

String strCountries = String.valueOf(lead.Source_Country_s_A_L__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

strCountries = String.valueOf(lead.Source_Country_s_M_Z__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

Boolean matchFound = false;

for(String selectedCountry:selectedCountries)

{

for(String compareToCountry:compareCountries){

if(selectedCountry == compareToCountry){

matchFound = true;

break;

}

}

if(matchFound)

break;

}

if(matchFound)

lead.Source_Country_Notification__c = errorMessage.toUpperCase();

else

lead.Source_Country_Notification__c = '';

//Destination Country Check

selectedCountries.clear();

strCountries = String.valueOf(lead.Destination_Country_s_A_L__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

strCountries = String.valueOf(lead.Destination_Country_s_M_Z__c);

if(strCountries != null && strCountries != '')

selectedCountries.addAll(strCountries.split(';'));

matchFound = false;

for(String selectedCountry:selectedCountries)

{

for(String compareToCountry:compareCountries){

if(selectedCountry == compareToCountry){

matchFound = true;

break;

}

}

if(matchFound)

break;

}

if(matchFound)

lead.Destination_Country_Notification__c = errorMessage.toUpperCase();

else

lead.Destination_Country_Notification__c = '';

}

}

 

What is the issue with before update? I want the same functionality regardless of insert or update. 

 

Thank you for any assistance!!! 

  • October 20, 2009
  • Like
  • 0