Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am trying to learn FieldSet from this Salesforce document but i am getting the following Error while saving this class

public class MerchandiseDetails {

public Merchandise__c merch { get; set; }

public MerchandiseDetails() {
    this.merch = getMerchandise();
}

public List<Schema.FieldSetMember> getFields() {
    return SObjectType.Merchandise__c.FieldSets.Dimensions.getFields();
}

private Merchandise__c getMerchandise() {
    String query = 'SELECT ';
    for(Schema.FieldSetMember f : this.getFields()) {
        query += f.getFieldPath() + ', ';
    }
    query += 'Id, Name FROM Merchandise__c LIMIT 1';
    return Database.query(query);
}}

Error: MerchandiseDetails Compile Error: dimensions is not a fieldSet of Merchandise__c at line 10 column 16

should i need do extra settings to enable FieldSet?

Thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

https://ap1.salesforce.com/help/doc/en/fields_editing_field_sets.htm

For your Merchandise_c Object you will need to configure your fieldset.The above example in salesforce guide assumes you already have a fieldset named Dimensions for your Merchandise_c Object.

refre the above link on how to create fieldsets in salesforce for an object and make sure you refer same name as you assign in fieldset in your apex code .

share|improve this answer
    
yes, i solved it, i haven't add the 'Dimension' fieldset on Merchandise_c Object, but i cant gauge The fields in the "Available for the Field Set" option and actual use of FieldSet. –  Axaykumar Varu Jan 11 '13 at 5:05
1  
The actual usage is say you have used fieldset in your code and you have a visualforce page .Now say in future your business demands one more field on visualforce .You may not go to your code for this .Just drag the field in fieldset and code dynamically picks it up! –  Mohith Shrivastava Jan 11 '13 at 5:12
    
Thanks Monith kumar for make me understand!!,and Available for Field set says : "If a field is marked as Available for the Field Set, it exists in the field set, but the developer hasn't presented it on the packaged Visualforce page. Administrators can display the field after the field set is deployed by moving it from the Available column to the In the Field Set column." What it means? –  Axaykumar Varu Jan 11 '13 at 5:15
1  
There are two columns.1)Available column -This displays all the fields available for fieldset 2)Fieldset column which an admin adds a field from availabel columns .Say you mark field while creating package as available for fieldset then later an admin can add that in fieldset column if that has to be presented on visualforce page . –  Mohith Shrivastava Jan 11 '13 at 5:23
    
Thanks Mohit kumar.. –  Axaykumar Varu Jan 11 '13 at 5:26

You have not added dimensions field set on your Merchandise__c object. Create dimensions field set and your problem will be resolved.

And second thing in your getMerchandise() method you have hard coded Id and name fields, it should not be there. If someone comes and add ID or name field explicitly in your field set in that case in your query there would be 2 ID or name fields and your code will fail.

so the code should be like this -

private Merchandise__c getMerchandise() {
    String query = 'SELECT ';
    integer i = 0;
    for(Schema.FieldSetMember f : this.getFields()) {
         if (i == 0) {
            query += f.getFieldPath();  
          }
          else {
            query +=  ', ' + f.getFieldPath(); 
          }
            i++;
     }       
    query += ' FROM Merchandise__c LIMIT 1';
    return Database.query(query);
}
share|improve this answer
    
thanks pramod for your point towards query, but this just i am learning.. –  Axaykumar Varu Jan 11 '13 at 8:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.