• Mukul
  • NEWBIE
  • 200 Points
  • Member since 2009

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 58
    Replies

Here are the parts I am using.

 

public Double totalDeposit { get; set;} {totalDeposit = 0.0;}

 

 

for(SFDC_520_QuoteLine__c mql : [Select s.Unit_Net_Price__c,s.Qty_Ordered__c,s.Product2__r.Fee_Type__c From SFDC_520_QuoteLine__c s]) { if(mql.Optional_Item__c==false && (mql.Product2__r.Fee_Type__c=='One Time Setup' || mql.Product2__r.Fee_Type__c=='Monthly Fee') ) { totalDeposit += mql.Unit_Net_Price__c * mql.Qty_Ordered__c; } }

 

 

<apex:outputText value="{!totalDeposit}"/>

 

 

Hi all,

 

I have a selectList and I am populating the values of the pick list by doing an AJAX call to a function in the controller. It all works fine but when i try to edit the values on the form and click on the submit button, it gives me an error "Value is not valid.". It forgets what the picklist values are when i click the submit button.

 

Any help is appreciated!!

 

Regards

Mukul

  • October 22, 2009
  • Like
  • 0

Hi all,

 

I have a dynamic query which returns me some field names 

 

public List<leadStore> getStoredLeadVals() { String myId = getRuleSetId(); String limitClause = ApexPages.currentPage().getParameters().get('lt'); System.debug('LIMIT VAL: ' + limitClause); String query; query = 'select lead_id__c, score__c, map__c '+ ' from lead_store__c ' + ' where ruleSetId__c =\'' + myId + '\' order by lead_id__c limit ' +limitClause; System.debug('Query:' + query); List<lead_store__c> storedLeads = Database.Query(query); String AllIds = ''; String AllIds1 = ''; for (lead_store__c lsc : storedLeads) { AllIds += '\'' + lsc.lead_id__c + '\','; } AllIds1 = AllIds.substring(0, AllIds.length()-1); String allFldNames = ''; // TODO: Get me the fieldNames from the scoringRule List. // Store it in a Map so that we see only right values Map<String, String> ruleNamesMap = new Map<String, String>(); List<ScoringRule__c> scoringFlds = [select rulename__c, Id from ScoringRule__c where RuleSetId__c =: myId]; for(ScoringRule__c s : scoringFlds) { ruleNamesMap.put(s.ruleName__c, s.Id); } Set <String> s = ruleNamesMap.keyset(); for (string si : s) { allFldNames += si + ','; } String lstQry = 'select id, '+ allFldNames + ' name from lead where id in ('+ allIds1+ ')'; System.debug('Lead qry: ' + lstQry); List<Lead> ldSto = Database.Query(lstQry); for (Lead l : ldSto) { for (lead_store__c lsc : storedLeads) { if (lsc.lead_id__c == String.valueOf(l.Id)) { lSt.add(new leadStore(lsc,l)); } } } return lSt; }

 

I want to display the field names taht i get in this list on my visualforce page.

 

Any idea on how can i do that? Any help is much appreciated!!

 

 

Regards

Mukul

 

 

  • August 20, 2009
  • Like
  • 0

Hello all,

 

I am trying to achieve this:

 

I have a param thats passed through URL. The param is essentially a lead's field name which is picklist e.g.  Industry and so on.

 

I want to get these picklist values in a list.

 

Here is how am i doing it:-

 

String lookup = ApexPages.currentPage().getParameters().get('lookup'); Schema.DescribeFieldResult F; sObject s = new Lead(); // Get the sObject describe result for the Account object Schema.DescribeSObjectResult r = Lead.sObjectType.getDescribe(); // TODO: Get it dynamically if (lookup == 'Industry') { F = Lead.Industry.getDescribe(); } if (lookup == 'leadsource') { F = Lead.leadsource.getDescribe(); } if (lookup == 'Productinterest__c') { F = Lead.Productinterest__c.getDescribe(); } if (lookup == 'status') { F = Lead.status.getDescribe(); } if (lookup == 'Salutation') { F = Lead.Salutation.getDescribe(); } if (lookup == 'rating') { F = Lead.rating.getDescribe(); }

 

 

 

 However i dont want to hardcode the lookup value in If statements. Is there any way i can do a getDescribe dynamically on the leads field?

 

like - Lead.getFieldName(Lookup).getDescribe() ?

 

Thanks much!

Regards

Mukul 

  • August 07, 2009
  • Like
  • 0

Hi all,

 

I have a problem where i am trying to prefill a custom object whenever the Edit Button is clicked.

 

Here is my Controller Code. I am instantiating object in the constructor class. I pass the ID of the object through the URL:

 

public class newScoreRuleController { // Declarations public List<ScoringRule__c> ScoringRule { get; private set;} public List<MappingRule__c> mappingRule {get; private set;}public newScoreRuleController () { // Give me blank lines of my Object String op = ApexPages.currentPage().getParameters().get('op'); ScoringRule = new List<ScoringRule__c>(); for (integer i = 0; i < 8; i++) { ScoringRule.add( new ScoringRule__c() ); } if (op!='edit') { MappingRule = new List<MappingRule__c>(); for (integer i = 0; i < 4; i++) { MappingRule.add( new MappingRule__c() ); } } else {// Edit Operation chosen .. So prefill it MappingRule = new List<MappingRule__c>(); MappingRule.add([Select rating__c, ScoreVal2__c, ScoreVal1__c, ScoreOperator2__c, ScoreOperator1__c, RuleSetId__c, Mapping_Field__c From mappingRule__c n where RuleSetId__c =: getRuleSetId()]); //MappingRule = mp; }}

 

 // Get me the Rule Set ID

 public String getRuleSetId() {

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

    return ruleId;

  } 

}

 

  Here is my Visualforce Code:

 

 

<apex:dataTable value="{!mappingRule}" var="mr"> <apex:column > <apex:facet name="header">Score</apex:facet> <apex:outputText value="Score"/> </apex:column> <apex:column > <apex:facet name="header">Operator</apex:facet> <apex:inputField value="{!mr.ScoreOperator1__c}"/> </apex:column> <apex:column > <apex:facet name="header">Score Value 1</apex:facet> <apex:inputText value="{!mr.ScoreVal1__c}"/> </apex:column> <apex:column > <apex:facet name="header">Operator</apex:facet> <apex:inputField value="{!mr.ScoreOperator2__c}"/> </apex:column> <apex:column > <apex:facet name="header">Score Value 2</apex:facet> <apex:inputText value="{!mr.ScoreVal2__c}"/> </apex:column> <apex:column > <apex:facet name="header">Rating</apex:facet> <apex:inputField value="{!mr.rating__c}"/> </apex:column> </apex:dataTable>

 

However it doesnt prefill the Object.  It doesnt complain either. So i really dont know whats happening?

 

Any help is appreciated!!! 

 

Regards

Mukul 

 

  • August 03, 2009
  • Like
  • 0

Hi all,

 

I have a visualforce page that i would like to prefill if the operation selected is Edit.

 

However i am facing this issue. If i prefill it, then i am unable to save the changes :

 

Here is the example:

<apex:page controller="newScoreRuleController" tabStyle="Scoring_Rule_Wizard__tab"> <apex:sectionHeader title="Create New Scoring Rule Set" help="/apex/scoringRuleAppHelp"/> <apex:form > <apex:pageBlock title="Rule Set" mode="edit"> <apex:messages styleClass="error" /> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel value="Rule Set Name:" for="ruleSetName"/> <apex:outputPanel layout="block" styleClass="requiredInput"> <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:inputText value="{!RuleSetName1}" id="ruleSetName" required="true"/> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Rule Set Comment:" for="ruleSetComment"/> <apex:outputPanel layout="block" styleClass="requiredInput"> <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:inputText value="{!ruleSetComment1}" id="ruleSetComment" required="true"/> </apex:outputPanel>

 Here is my Controller Code:

 

 

// Get me the Rule Set ID public String getRuleSetId() { String ruleId = ApexPages.currentPage().getParameters().get('id'); return ruleId; } public string getRuleSetName1() { String op = ApexPages.currentPage().getParameters().get('op'); if (op != 'edit') { } else { RuleSet__c ruleset = [select ruleSet__c from RuleSet__c where id =: getRuleSetId()]; String rulesetname = ruleset.RuleSet__c; this.RuleSetName1 = rulesetname; } return this.RuleSetName1; } public string getRuleSetComment1() { String op = ApexPages.currentPage().getParameters().get('op'); if (op != 'edit') { return this.RuleSetComment1; } else { RuleSet__c ruleset = [select ruleSetComment__c from RuleSet__c where id =: getRuleSetId()]; String rulesetcomment = ruleset.RuleSetComment__c; return rulesetcomment; } }

 

 

 

 Any help is much appreciated!!

 

 

 


 

  • July 31, 2009
  • Like
  • 0

Hi all,

 

I have a picklist field that has different options like; Cotnains, Greater than, Less than and so on.

 

I want to show different options dependent on what is beign passed in the URL - like if the field is a Number field then i dont want to show Contains and other String Operation Options.

 

I know that we can do picklist dependencies in an object byt is there any way i can do a picklist dependency on a param?

 

Regards

Mukul

  • July 29, 2009
  • Like
  • 0

Hi all,

 

I have a custom input field called Start Date and i want to use a calander widget on it.

 

Any pointers on how to do that in Visualforce?

 

Here is where i would want to attach it...Any help is much appreciated!

 

 

<apex:pageBlockSectionItem > <apex:outputLabel value="Start date(YYYY-MM-DD):" for="startDate"/> <apex:outputPanel layout="block" styleClass="requiredInput"> <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:inputText value="{!startDate}" id="startDate" required="true"/> </apex:outputPanel> </apex:pageBlockSectionItem>

 

 Thanks!

Mukul

 

  • July 26, 2009
  • Like
  • 0

Hi all,

 

Can anyone help me out in writing a unit test for constructor method? I am very new to writing test methods. Please help!!

 

Here is the snippet of the controller constructor code:

 

// Constructor Method public newScoreRuleController () { // Give me blank lines of my Object ScoringRule = new List<ScoringRule__c>(); for (integer i = 0; i < 5; i++) { ScoringRule.add( new ScoringRule__c() ); } }

 

 Thanks in advance!

Regards

Mukul

 

  • July 21, 2009
  • Like
  • 0

Hi all,

 

Is there any Salesforce Library that i can use to utilize this feature in Custom Reports? Like if i pick a field that is a picklist for e.g. Industry, it shows a little search box kind of button on the right hand side of the input field which on clicking opens a new window which gives all options of that field.

 

Any help is appreciated!!

 

Regards

Mukul 

  • July 21, 2009
  • Like
  • 0

Hi all,

 

I have this issue where i am unable to pass the param from the VF to Controller. It shows Null when i try to print it out.

 

Here is my VF Code:

 

<table width="100%"> <th> Rule Name </th> <th> Action </th> <apex:repeat value="{!ruleNameList}" var="ruleNameList"> <tr> <apex:repeat value="{!ruleNameList}" var="ruleNameLsit1"> <td><apex:outputText value="{!ruleNameList}"/></td> <td> <apex:repeat value="{!ruleNameList}" var="ruleNameLsit1"> <apex:commandLink value="Edit / " action="{!editRule}"/> <apex:commandLink action="{!deleteRule}" onClick="confirmCancel();" value="Delete" id="theCommandLink3"> <apex:param value="{!ruleNameList}" id="param" assignTo="{!param}"/> </apex:commandLink> </apex:repeat> </td> </apex:repeat> </tr> </apex:repeat> </table>

 

 Here is my Controller Code:

 

public String param {get; set;} // Delete Rules public PageReference deleteRule(){ String id = getRuleSetId(); System.debug('RULENAME: ' + param + ', RULEID: ' + id); // delete all rules associated with it List <ScoringRule__c> scoringrules = [Select Id From ScoringRule__c Where RuleName__c =: param and RuleSetId__c =: id ]; delete scoringrules; return null; } public List<String> getRuleNameList() { String ruleId = getRuleSetId(); // System.debug('In getRuleNameLsit'); List<ScoringRule__c> rulenames = [select ruleName__c, Id from scoringRule__c where ruleSetId__c =: ruleId]; // Save it in a Map so that we can eliminate duplicates Map<String, String> ruleNamesMap = new Map<String, String>(); for(ScoringRule__c s : rulenames) { ruleNamesMap.put(s.ruleName__c, s.Id); } List <String> ruleNamesList = new List<String>(); // Return it in a form which will be compatible with it Set <String> s = ruleNamesMap.keyset(); for (String si : s) { ruleNamesList.add(si); } return ruleNamesList; }

 

Any help is appreciated!!

 

Thanks in advance

Muku

 

 

  • July 18, 2009
  • Like
  • 0

Hi all,

 

I had this page absoultely working before. I didnt make any changes to the code and it has stopped working.

 

I have a custom object that has this field - ScoringRule_Rule1__c (picklist).

 

On visualforce page, it keeps complaining that it cant bind an inputField to something that is not an object's field.

 

Here is my Controller code:

 

public class newScoreRuleController {

// Declarations
public List<ScoringRule__c> ScoringRule { get; private set;}

// Constructor Method
public newScoreRuleController () {
// Give me blank lines of my Object
ScoringRule = new List<ScoringRule__c>();
for (integer i = 0; i < 5; i++) {
ScoringRule.add( new ScoringRule__c() );
}

}
}

 Here is my Visualforce Code:

 

<apex:page controller="newScoreRuleController" tabStyle="Lead">
<apex:sectionHeader title="Scoring Rule Wizard" subtitle="Step 2 of 2"/>
<apex:form >
<apex:pageBlock title="Choose a scoring rule" mode="edit">
<apex:messages styleClass="error" />
<apex:pageBlockSection title="Choose a scoring rule">
<apex:pageBlockTable value="{!ScoringRule}" var="sr" id="theTable" rowClasses="odd,even"
styleClass="tableClass" rows="5">
<apex:column >
<apex:facet name="header">Field</apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{!fieldName}"/>
</apex:column>
<apex:column width="25%">
<apex:facet name="header">Operator 1</apex:facet>
<apex:outputPanel layout="block" styleClass="requiredInput">
<apex:outputPanel layout="block" styleClass="requiredBlock"/>
<apex:inputField value="{!sr.ScoringRule_Rule1__c}" required="true"/>
</apex:outputPanel>
</apex:column>
</apex:pageBlockTable>

<!-- Within a pageBlockSection, inputFields always display with their
corresponding output label. -->
</apex:pageBlockSection>

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

 

Any help is much appreciated!

 

Regards

Mukul

 

 

 

 

  • July 09, 2009
  • Like
  • 0

Hi all,

 

Can i create a new field in the lead object through my Apex controller class?

 

 

  • June 23, 2009
  • Like
  • 0

Hi all,

 

I dont know what am i doing wrong. Probably an extra pair of eyes might help. I have this dynamic SOQL query and I am getting the values from the VisualForce Page. But somehow i dont see anything on the page:

 

Here is my controller Code:

 

public With Sharing class newScoreRuleController { public List<ScoringRule__c> ScoringRule { get; private set;} public List<showLeads> searchResults = new List<showLeads>(); String ViewBy = ''; String fldDate; Date StartDate; Date EndDate; public string getViewBy() { return this.ViewBy; } public String getFldDate() { return this.fldDate ; } public Date getStartDate() { return this.StartDate ; } public Date getEndDate() { return this.EndDate ; } public void setViewBy(string val) { this.ViewBy = val; } public void setFldDate(String val) { this.fldDate = val; } public void setStartDate(Date val) { this.StartDate = val; } public void setEndDate(Date val) { this.EndDate = val; } // Add leads Options
public List<SelectOption> getLeadView() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('myleads','My Leads'));
options.add(new SelectOption('myteamleads','My Team Leads'));
options.add(new SelectOption('alleads','All Leads'));
return options;
}

// Get Date Options
public List<SelectOption> getDateOptions() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('CreatedDate','Created Date'));
options.add(new SelectOption('lastModifiedDate','Last Modified'));
options.add(new SelectOption('lastAcitivityDate','Last Acitivty'));
return options;
}

 

public List<Lead> getLead() { if(lead == null) lead = new Lead(); // Get Leads based on the selected Value String leadQry = 'select FirstName, LastName, NumberOfEmployees,' + 'AnnualRevenue from lead where ' + ViewBy + ' >= ' + StartDate + ' and ' + ViewBy + ' <= ' + EndDate; System.debug('************ Query: ************ ' + leadQry); List <Lead> leads = Database.Query(leadQry); return leads; } public String ApplyScoringRule() { // Now set the method depending on what it is; List<Lead> results = getLead(); // If zero or more than 250 records returned, display a message if (results.size() == 250) ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'NOTE: Only the first 250 rows are displayed.')); if (results.size() == 0) ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'NO RECORDS FOUND.')); // Build the searchResults[] list used by the Apex:DataTable tag on the page for (Lead c : results) { // System.Debug(); searchResults.add( new showLeads(c) ) ; } return null; } Public Class showLeads{ public boolean selected = true; public Lead l = null; public showLeads() { } public showLeads(Lead lr) { lr = l; } public Lead getShowLeads() { return this.l ; } public void setShowLeads(Lead ls) { this.l = ls; } } }

 

 Here is my Visual Controller Code:

 

<apex:page controller="newScoreRuleController" tabStyle="Lead"> <apex:sectionHeader title="Score your leads"/> <apex:form > <apex:pageBlock title="Select Leads that you want to score" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!applyScoringRule}" value="Apply Scoring Rule"/> <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Selection Criteria"> <apex:outputLabel value="Date:"/> <apex:selectList id="date" multiselect="false" value="{!fldDate}" required="true" size="1"> <apex:selectOptions value="{!dateOptions}"></apex:selectOptions> </apex:selectList> <apex:outputLabel value="Start date:" for="startDate"/> <input id="startDate" name="startDate" value="{!$CurrentPage.parameters.startDate}" size="7" maxlength="10" />(yyyy-mm-dd) &nbsp;&nbsp;&nbsp; <apex:outputLabel value="End date:" for="endDate"/> <input id="endDate" name="endDate" value="{!$CurrentPage.parameters.endDate}" size="7" maxlength="10" />(yyyy-mm-dd) <!-- Within a pageBlockSection, inputFields always display with their corresponding output label. --> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

 Any help is appreciated!!

 

Thanks again!

 

 

  • June 22, 2009
  • Like
  • 0

Hi all,

 

I have a query where i am getting the fieldname dynamically from a peice of code. Then i have a loop and i want to access that field's value. Its not letting me do that. 

 

Here is my code -

 

       String leadquery = 'select ' + fldName + ' from lead';
         List <Lead> leads = Database.Query(leadquery);
    for (Lead lead : leads) {


     Integer val_fld = Integer.valueOf(lead.fldName);

    // Do something

    }

 

It doesnt let me do lead.fldName bcause it says "Invalid field fldName for sObject lead." Can anyone tell me how can i do it dynamically?

 

Any help is much appreciated.

  • June 19, 2009
  • Like
  • 0

i have an object called ScoringRule. ScoringRule has these fields - FldName, Operator1, Val1, Operator2, Val2, Score. This would return me more than 1 record. 

 

How can i loop through the records? I dont want to display it on a page but i want to compare the fieldName__c with the lead object's field and apply some logic to it.

 

So i will have 2 queries:

     // Get me the result from the query
        ScoringRule__c score = [Select n.fieldName__c,
                           n.Val2__c, n.ScoringRule_Rule1__c, ScoringRule_Val1__c,
                           n.Score__c, n.Rule2__c
                           FromScoringRule__c n
                           where n.Val2__c != '' 
                           and n.fieldName__c!='']; 

 

 Lead lead = [select FirstName, LastName, NumberOfEmployees, AnnualRevenue from lead]

 

I want to compare the fieldName__c with the the fields returned by the lead query.

 

Any help would be appreciated.

 

Regards

  • June 19, 2009
  • Like
  • 0

I am very new to Apex Development. I am trying to accomplish this: 

 

I have 1 custom object: ScoringRule__c and its fields are leadName__c, operator1__c, operator2__c, val1__c, val2__c, score__c

leadName__c stores the field name of the lead (Annual Revenue/No.OfEmployees etc.)

operator1__c and operator2__c stores the operater (greater than, less than etc.)

Va1_c and Val2_c store the values (any number).

In english, it would appear like this:

If the Annual revenue is greater than 0 and less than 100, give it a score of A.

 

I want to write a query that takes the lead object and gives me all leads that will have revenue between 0 to 100. 

 

Can i do that? Can anyone please help me out?

  • June 17, 2009
  • Like
  • 0

Hi all,

 

I have a save method in my Controller. I want to save all fields in my object. I am able to save everthing except one. Everyother field is maintaining its state in the object's instance. All those are being saved properly.

 

I am passing one field through a parameter in URL. How can i save that field in my object?

 

Here is the snippet of my save method:

public With Sharing class newScoreRuleController { Lead lead; public List<ScoringRule__c> ScoringRule { get; private set;} public newScoreRuleController () { ScoringRule = new List<ScoringRule__c>(); ScoringRule.add( new ScoringRule__c() ); ScoringRule.add( new ScoringRule__c() ); ScoringRule.add( new ScoringRule__c() ); ScoringRule.add( new ScoringRule__c() ); ScoringRule.add( new ScoringRule__c() ); } public PageReference save() { scoringRule.fieldName__c = ApexPages.currentPage().getParameters().get('fld'); insert ScoringRule; return null; } }

 

Here is the snippet of my visualforce page:

 

<apex:pageBlockTable value="{!ScoringRule}" var="sr" id="theTable" rowClasses="odd,even" styleClass="tableClass" rows="5"> <apex:column > <apex:facet name="header">Field</apex:facet> <apex:facet name="footer"></apex:facet> <apex:outputText value="{!fieldName}"/> </apex:column> <apex:column width="25%"> <apex:facet name="header">Rule 1</apex:facet> <apex:inputField value="{!sr.ScoringRule_Rule1__c}"/> </apex:column> <apex:column width="25%"> <apex:facet name="header">Value 1</apex:facet> <apex:inputText value="{!sr.ScoringRule_Val1__c}"/> </apex:column> <apex:column width="25%"> <apex:facet name="header">Rule 2</apex:facet> <apex:inputField value="{!sr.Rule2__c}"/> </apex:column> <apex:column width="25%"> <apex:facet name="header">Value 2</apex:facet> <apex:inputField value="{!sr.Val2__c}"/> </apex:column> <apex:column width="25%"> <apex:facet name="header">Score</apex:facet> <apex:inputField value="{!sr.Score__c}"/> </apex:column> </apex:pageBlockTable>

 

Any help will be appreciated!! Thanks in advance!

 

 

 

  • June 17, 2009
  • Like
  • 0

Hi all,

 

I have this issue where i cant display my custom object;s fields on the page. Can anyone help me out?

 

Here is my Controller Code:

 

public class newScoreRuleController {

public List<ScoringRule__c> ScoringRule { get; private set;}

public String getFieldName() {
String s = ApexPages.currentPage().getParameters().get('fld');
return s;
}

public List<SelectOption> GetFieldsForObject(Map<String, Schema.SObjectField> objFields, string lblPrefix, string fldPrefix) {
// Build a list of field names to use to iterate the Map of field object pointers
Set <string> flds = new Set <String>();
flds = objFields.keySet();

// Add the keyset of field names to a list so that it can be sorted
List<String> fldList = new List<String>();
for (string f : flds) {
fldList.add(f);
}
fldList.sort();

List<SelectOption> options = new List<SelectOption>();
for (string f : fldList) {
string fldName = objFields.get(f).getDescribe().getName();
string fldLabel = objFields.get(f).getDescribe().getLabel();
string fldType = ('' + objFields.get(f).getDescribe().getType()).replace('Schema.DisplayType.', '') ;
if (fldType <> 'REFERENCE' && fldType <> 'ID' && fldName <> 'IsDeleted' && fldName <> 'SystemModstamp') options.add(new selectOption(fldType + '/' + fldPrefix + fldName, lblPrefix + fldLabel ));
if (fldName == 'OwnerID') {
options.add(new selectOption('STRING/' + fldPrefix + 'Owner.Name', lblPrefix + 'Owner.Name'));
options.add(new selectOption('STRING/' + fldPrefix + 'Owner.Alias', lblPrefix + 'Owner.Alias'));
options.add(new selectOption('STRING/' + fldPrefix + 'Owner.Department', lblPrefix + 'Owner.Department'));
options.add(new selectOption('STRING/' + fldPrefix + 'Owner.Division', lblPrefix + 'Owner.Division'));
} else if (fldName == 'LastModifiedByID') {
options.add(new selectOption('STRING/' + fldPrefix + 'LastModifiedBy.Name', lblPrefix + 'LastModifiedBy.Name'));
options.add(new selectOption('STRING/' + fldPrefix + 'LastModifiedBy.Alias', lblPrefix + 'LastModifiedBy.Alias'));
} else if (fldName == 'CreatedByID') {
options.add(new selectOption('STRING/' + fldPrefix + 'CreatedBy.Name', lblPrefix + 'CreatedBy.Name'));
options.add(new selectOption('STRING/' + fldPrefix + 'CreatedBy.Alias', lblPrefix + 'CreatedBy.Alias'));
}
}

return options;
}


public List<SelectOption> getLeadFields() {
Map<String, Schema.SObjectField> leadFields = Schema.SObjectType.Lead.fields.getMap();
newScoreRuleController critClass = new newScoreRuleController();
//searchCriteria critClass = new searchCriteria();
// Return SelectOption lists for the Contact and Account objects
List<SelectOption> sel1 = critClass.GetFieldsForObject(leadFields, '', '');
List<SelectOption> options = new List<SelectOption>();
options.add(new selectOption('', '- select field -'));
for (Selectoption selOpt : sel1) {
options.add(selOpt);
}
return options;
}

public List<SelectOption> getScoreRules() {
List<SelectOption> options = new List<SelectOption>();
options.add(new selectOption('eq', 'Equals'));
options.add(new selectOption('ne', 'Not Equal'));
options.add(new selectOption('gt', 'Greater Than'));
options.add(new selectOption('ge', 'Greater or Equal To'));
options.add(new selectOption('lt', 'Less Than'));
options.add(new selectOption('le', 'Less or Equal To'));
options.add(new selectOption('starts', 'Starts With'));
options.add(new selectOption('contains', 'Contains'));
options.add(new selectOption('notcontain', 'Does Not Contain'));
options.add(new selectOption('in', 'Includes'));
options.add(new selectOption('notin', 'Excludes'));
return options;
}

public List<SelectOption> getScoreVal() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('A','A'));
options.add(new SelectOption('B','B'));
options.add(new SelectOption('C','C'));
return options;
}

public List<SelectOption> getWeightList() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('0','0'));
options.add(new SelectOption('1','1'));
options.add(new SelectOption('2','2'));
options.add(new SelectOption('3','3'));
options.add(new SelectOption('4','4'));
options.add(new SelectOption('5','5'));
options.add(new SelectOption('6','6'));
options.add(new SelectOption('7','7'));
options.add(new SelectOption('8','8'));
options.add(new SelectOption('9','9'));
return options;
}

public PageReference step1() {
return Page.scoreRuleStep1;
}

public PageReference step2() {
// Save some stuff here
// Pass it through URL to the next page
return Page.scoreRuleStep2;
}

public PageReference cancel() {
PageReference leadsPage = new ApexPages.StandardController(lead).view();
leadsPage.setRedirect(true);
return leadsPage;
}


public PageReference save() {
PageReference leadPage = new ApexPages.StandardController(lead).view();
leadPage.setRedirect(true);
return leadPage;
}

}

 Here is my Visual Force Code:

 

<apex:page controller="newScoreRuleController" tabStyle="Lead">
<script>
function confirmCancel() {
var isCancel = confirm("Are you sure you wish to cancel?");
if (isCancel) return true;

return false;
}
</script>
<apex:sectionHeader title="Scoring Rule Wizard" subtitle="Step 2 of 2"/>
<apex:form >
<apex:pageBlock title="Choose a scoring rule" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="/apex/scoreRuleStep1" value="Previous"/>
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"
onclick="return confirmCancel()" immediate="true"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Choose a scoring rule">
<apex:pageBlockTable value="{!ScoringRule}" var="sr" id="theTable" rowClasses="odd,even"
styleClass="tableClass" rows="5">
<apex:column >
<apex:facet name="header">Field</apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{!fieldName}"/>
</apex:column>
<apex:column width="25%">
<apex:facet name="header">Rule 1</apex:facet>
<apex:inputField value="{!sr.ScoringRule_Rule1__c}"/>
</apex:column>
<apex:column width="25%">
<apex:facet name="header">Value 1</apex:facet>
<apex:inputText value="{!sr.ScoringRule_Val1__c}"/>
</apex:column>
<apex:column width="25%">
<apex:facet name="header">Rule 2</apex:facet>
<apex:inputField value="{!sr.Rule2__c}"/>
</apex:column>
<apex:column width="25%">
<apex:facet name="header">Value 2</apex:facet>
<apex:inputField value="{!sr.Val2__c}"/>
</apex:column>
</apex:pageBlockTable>

<!-- Within a pageBlockSection, inputFields always display with their
corresponding output label. -->
</apex:pageBlockSection>

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

 

I am very new to Apex code development. 

  • June 16, 2009
  • Like
  • 0

Hi all,

 

I have a custom object that has a few fields - 3 picklists and 2 texts.

 

I want to display the fields the objects fields like we see in the custom report filter.

 

Can anyone point me on how can i do it?

 

Thanks much in advance!

  • June 13, 2009
  • Like
  • 0

Hi all,

 

I am very new to the Apex development and  CustomControllers.

 

I am building a "Custom Report" like application where you can choose some operators and create a filter.

 

On clicking the Save button, i want to save that filter in a record in an object. Can anyone please tell me what should my save function look like?

 

Here is my visual page code : 

 <apex:page controller="newScoreRuleController" tabStyle="Lead">
  <script type="text/javascript">
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;  
     return false;
  }  
  </script>
  <apex:sectionHeader title="Scoring Rule Wizard" subtitle="Step 1 of 2"/>
    <apex:form id="myform">
     <apex:pageBlock title="Select a Lead's value" mode="edit" id="pgB">
   
        <apex:pageBlockButtons >
          <apex:commandButton value="Next" onclick="moveToNext(); "/>
          <apex:commandButton action="{!cancel}" value="Cancel"
                              onclick="return confirmCancel()" immediate="true"/>
                             
        </apex:pageBlockButtons>
         <apex:pageBlockSection title="Select a lead's field" id="pgBS">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
        <apex:selectList id="fldName" multiselect="false" required="true">
        <apex:selectOptions value="{!leadFields}"></apex:selectOptions>
          <script type="text/javascript">
        function leadChosen() {
   var selectedVal = document.getElementById('{!$Component.fldName}').value;
   var isChosen = alert(selectedVal + ' is chosen');
   if (isChosen) return true;   
   return false;
  }
  function moveToNext() {
     var selectedVal = document.getElementById('{!$Component.fldName}').value;
     parent.document.location.href = "https://nl.na6.visual.force.com/apex/scoreRuleStep2?fld=" + selectedVal;
    //return selectedVal;
  }
     </script>
        </apex:selectList>
          <apex:selectList id="wtList" multiselect="false" value="{!}" required="true">
        <apex:selectOptions value="{!weightList}"></apex:selectOptions>
         </apex:selectList>
      </apex:pageBlockSection>
          </apex:pageBlock>
           </apex:form>
       </apex:page>

 

Here is my controller code: 

 

public class newScoreRuleController {

  Lead lead;
  public Lead getLead() {
   if(lead == null) lead = new Lead();
   return lead;
  }
 
  public String getFieldName() {
   String s = ApexPages.currentPage().getParameters().get('fld');
   return s;
  }
 
  public List<SelectOption> getLeadFields() {
   List<SelectOption> options = new List<SelectOption>();
   options.add(new SelectOption('AnnualRevenue','Annual Revenue'));
   options.add(new SelectOption('Title','Title'));
   options.add(new SelectOption('No.OfEmployees','No. Of Employees'));
   return options;
  }
 
 
  public PageReference step1() {
   return Page.scoreRuleStep1;
  }
 
  public PageReference step2() {
   return Page.scoreRuleStep2;
  }
 
    public PageReference cancel() {
     PageReference leadsPage = new ApexPages.StandardController(lead).view();
     leadsPage.setRedirect(true);
     return leadsPage;
  }


  public PageReference save() {
   // Create an object and save the rule and field there
   // TODO: Save an object
  // Dont know what should be done here  

  // scoringRule__c myScoringRule = new scoringRule__c();
  // myScoringRule.Annual Revenue = lead.Revenue;
   PageReference leadPage = new ApexPages.StandardController(lead).view();
   leadPage.setRedirect(true);
   return leadPage;
 }

}

  • June 05, 2009
  • Like
  • 0

Hi all,

 

I have a selectList and I am populating the values of the pick list by doing an AJAX call to a function in the controller. It all works fine but when i try to edit the values on the form and click on the submit button, it gives me an error "Value is not valid.". It forgets what the picklist values are when i click the submit button.

 

Any help is appreciated!!

 

Regards

Mukul

  • October 22, 2009
  • Like
  • 0

Hi all,

 

I have a dynamic query which returns me some field names 

 

public List<leadStore> getStoredLeadVals() { String myId = getRuleSetId(); String limitClause = ApexPages.currentPage().getParameters().get('lt'); System.debug('LIMIT VAL: ' + limitClause); String query; query = 'select lead_id__c, score__c, map__c '+ ' from lead_store__c ' + ' where ruleSetId__c =\'' + myId + '\' order by lead_id__c limit ' +limitClause; System.debug('Query:' + query); List<lead_store__c> storedLeads = Database.Query(query); String AllIds = ''; String AllIds1 = ''; for (lead_store__c lsc : storedLeads) { AllIds += '\'' + lsc.lead_id__c + '\','; } AllIds1 = AllIds.substring(0, AllIds.length()-1); String allFldNames = ''; // TODO: Get me the fieldNames from the scoringRule List. // Store it in a Map so that we see only right values Map<String, String> ruleNamesMap = new Map<String, String>(); List<ScoringRule__c> scoringFlds = [select rulename__c, Id from ScoringRule__c where RuleSetId__c =: myId]; for(ScoringRule__c s : scoringFlds) { ruleNamesMap.put(s.ruleName__c, s.Id); } Set <String> s = ruleNamesMap.keyset(); for (string si : s) { allFldNames += si + ','; } String lstQry = 'select id, '+ allFldNames + ' name from lead where id in ('+ allIds1+ ')'; System.debug('Lead qry: ' + lstQry); List<Lead> ldSto = Database.Query(lstQry); for (Lead l : ldSto) { for (lead_store__c lsc : storedLeads) { if (lsc.lead_id__c == String.valueOf(l.Id)) { lSt.add(new leadStore(lsc,l)); } } } return lSt; }

 

I want to display the field names taht i get in this list on my visualforce page.

 

Any idea on how can i do that? Any help is much appreciated!!

 

 

Regards

Mukul

 

 

  • August 20, 2009
  • Like
  • 0

Hello all,

 

I am trying to achieve this:

 

I have a param thats passed through URL. The param is essentially a lead's field name which is picklist e.g.  Industry and so on.

 

I want to get these picklist values in a list.

 

Here is how am i doing it:-

 

String lookup = ApexPages.currentPage().getParameters().get('lookup'); Schema.DescribeFieldResult F; sObject s = new Lead(); // Get the sObject describe result for the Account object Schema.DescribeSObjectResult r = Lead.sObjectType.getDescribe(); // TODO: Get it dynamically if (lookup == 'Industry') { F = Lead.Industry.getDescribe(); } if (lookup == 'leadsource') { F = Lead.leadsource.getDescribe(); } if (lookup == 'Productinterest__c') { F = Lead.Productinterest__c.getDescribe(); } if (lookup == 'status') { F = Lead.status.getDescribe(); } if (lookup == 'Salutation') { F = Lead.Salutation.getDescribe(); } if (lookup == 'rating') { F = Lead.rating.getDescribe(); }

 

 

 

 However i dont want to hardcode the lookup value in If statements. Is there any way i can do a getDescribe dynamically on the leads field?

 

like - Lead.getFieldName(Lookup).getDescribe() ?

 

Thanks much!

Regards

Mukul 

  • August 07, 2009
  • Like
  • 0

Hi all,

 

Is there any Salesforce Library that i can use to utilize this feature in Custom Reports? Like if i pick a field that is a picklist for e.g. Industry, it shows a little search box kind of button on the right hand side of the input field which on clicking opens a new window which gives all options of that field.

 

Any help is appreciated!!

 

Regards

Mukul 

  • July 21, 2009
  • Like
  • 0

I'm setting up a few custom tab splash pages to introduce and explain custom objects in an app. I created these splash pages as Visualforce pages and linked them up through the Home > Custom Links section and applied them to the respective tabs.

 

The Visualforce page displays as the splash page, but the "don't show this message again" and "continue" buttons do not appear at the bottom. These buttons do display if I use a URL or s-control type custom link.

 

Are those buttons not currently supported on Visualforce splash pages, or does something need to be configured to enable them?

I am missing something basic here and I don't know what it is.  How do you get the "Continue" and "Don't show me this again" buttons to be incorporated into the page?

 

I've created a VF Page (mostly stock html thus probably missing a apex section or something) and set it up as a Home tab Custom Link and then set it as my splash page for my custom tab. The page shows fine, but there are no buttons to dismiss the splash because there are no buttons.

 

So, what am I missing?  The only information I could dig up in Help, Apex Help and VF Help is the following:

 


 

Custom Tab Splash Page

You can add a splash page to any custom tabs in your app. Custom splash pages can include information about using the custom tab and custom object with links to additional information. They include a Continue button and a Don’t show me this again button.
Create the splash page for your app in the form of a custom link for the Home tab via Setup | Customize | Home | Custom Links. Custom links can be a URL to an HTML page or a custom s-control or Visualforce page. Create your custom splash page as a Home tab custom link and then add it as the splash page option to any custom tabs you plan to upload to AppExchange

I have a client who is experiencing the following error on a custom controller and we can't find any solutions. 

 

It's just a selectList with a value tied to a String.

 

"j_id0:theForm:j_id2:j_id13:j_id14:j_id16:mySolutionOption: Validation Error: Value is not valid"

 

Any ideas?

 

Thanks,

Jon

Folk,

 

I am having one dropdown on Visual Force page. Onchange event i am creating new options for this select using java script. And for this select option one String varible on controller.

 

VF tag:

  <apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}">

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

 JS Funtion:

 

<script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script>

 

 

 

Controller:

 

public List<SelectOption> getPicklist(){ List<SelectOption> options = new List<SelectOption>{new SelectOption('Silambarasan','Silambarasan'),new SelectOption('Velu','Velu'),new SelectOption('Banu','Banu')}; return options; } public String testSelect {set;get;}

 

On clicking the save button i am getting the following error:

 

j_id0:form:block:myselect: Validation Error: Value is not valid

 

 Full code for VF PAge:

 

<apex:page standardController="VbApp__c" extensions="VBAPPController" ><script language='JavaScript'>function change(){alert('{!$Component.form.block.myselect}'); tbox = document.getElementById('{!$Component.form.block.myselect}'); clearlistbox(tbox); for(i=0; i < 5 ; i++) { var no = new Option(); no.value = 'karthi' + i; no.text = 'karthi' + i; tbox[i] = no; } } function clearlistbox(lb){ for (var i=lb.options.length-1; i>=0; i--){ lb.options[i] = null; } lb.selectedIndex = -1; }</script> <apex:form ID="form"> <apex:sectionHeader title="Welcom to VB Application"/> <apex:pageBlock id="block"> <apex:pageBlockButtons location="both"> <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> Name:<apex:inputText value="{!vbname}"/><br/> PickList: <apex:selectList size="1" multiselect="false"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> <br/> Myselect: <apex:selectList onchange="javascript:change()" id="myselect" size="1" value="{!testSelect}"> <apex:selectOptions value="{!picklist}"></apex:selectOptions> </apex:selectList> </apex:pageBlock> </apex:form></apex:page>

 and 

 

Example for page shows

 

After changed the dromdown. I am trying to save on this time I am gettingerror "j_id0:form:block:myselect: Validation Error: Value is not valid"

Hello. I have a custom VF component which contains an <apex:selectList> component, as follows:

 

<apex:component controller="picklistController" id="compPickList">
<apex:attribute name="SystemEntity" description="" type="String" required="true" default="Account" assignTo="{!systemObject}"></apex:attribute>
<apex:attribute name="picklistField" description="" type="String" required="true" default="Type" assignTo="{!picklist_Field}"></apex:attribute>
<apex:attribute name="value" description="" type="String[]" required="true"></apex:attribute>
<apex:selectList id="ddlPickList" value="{!value}" multiselect="true" size="4">
<apex:selectOptions value="{!pickListOptions}"></apex:selectOptions>
</apex:selectList>
</apex:component>

 

The component's controller is obvious, so am skipping it for now.

 

The component acceps two attributes which it uses to populate the selectList options. I am using this component in a page and it works fine, i.e. am able to retrieve the selected values from the component into the page as long as am working with the pre-populated options, the code is as follows:

 

 

<apex:page controller="sampleCon" id="myPage"> <apex:form id="myForm"> <c:sObjectFieldPicklistComponent id="accountPicklist" value="{!accountIndustry}" picklistField="Ownership" systemEntity="Account" /> <apex:commandButton value="Test" action="{!SaveValues}" /> </apex:form> </apex:page>

 

I am again skipping the page controller code as it's obvious, but do let me know if you want to see it.

 

Now, the problem starts when I add dynamic <option> to this multi-select picklist through JavaScript, am able to add them in the browser on the client side, but when I click on the command button to submit the user selected values, the previously working code breaks, the values are not submitted, the execution never enters the action function (in this case - SaveValues()), and I get a message in the System Log window:

 

myPage:myForm:accountPicklist:compPickList:ddlPickList: Validation Error: Value is not valid

 

Any idea what's happening here? I am suspecting that the system (not me) is checking the submitted values against the viewstate and is throwing an error somewhere which I am unable to trap and trace.

 

Can someone please explain this behavior, and if possible, a solution to get this thing going?

 

Thanks in advance!

Ajay

I have a new native app on the app exchange and a professional edition customer tried to install it. They got a bunch of errors like this:

 

Missing feature

Apex Classes

Installing this package requires the following feature and its associated permissions: Apex Classes

 

 

My app uses a few custom classes, objects, and a visualforce page. I was told that even a pro edition can install an app that uses custom apex classes. 

 

Does anyone have ideas of how to dig into this further?

 

Thanks!

  • February 20, 2009
  • Like
  • 0
Hi folks - I've got mixed answers on this one. If I create an AppExchange application that uses Apex Code as part of it, can I install that application into a customer's professional edition org?

If not, that would severely reduce the chance that we could actually use Apex Code since it would mean that we couldn't sell to a big chunk of customers.

Ryan