• John Samuels
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hey, I was wondering if there is a way to view all custom fields, fieldsets, validations rules, and so on I have created in my org.
I have an Apex class that creates a graph based off of a fieldset. It originally pulled from an Account fieldset (let's say the fieldset is called TestFieldSet). Here is relevant code:

public RadarChartController(ApexPages.StandardController controller){
acctId = controller.getRecord().Id;
}


public List<Schema.FieldSetMember> getFields() {
system.debug(SObjectType.Account.FieldSets.TestFieldSet.getFields());
return SObjectType.Account.FieldSets.TestFieldSet.getFields();
}


public List<Map<Object,Object>> getData() {
String query = 'SELECT ';
List<String> fieldNames = new List<String>();


for(Schema.FieldSetMember f : getFields()){
query += f.getFieldPath() + ', ';
fieldNames.add(f.getFieldPath());
}
query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1';


SObject myFieldResults = Database.Query(query);
Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();

However, I now want to pull a fieldset from another object. Call this TestFieldSet2. It is in custom object XYZ. However, the graph will still be displayed on an account record, so it needs to be associated with account ID in some way. I tried this code. Changes highlighted:

public RadarChartController(ApexPages.StandardController controller){
acctId = controller.getRecord().Id;
}


public List<Schema.FieldSetMember> getFields() {
system.debug(SObjectType.XYZ__c.FieldSets.TestFieldSet.getFields());
return SObjectType.XYZ__c.FieldSets.TestFieldSet.getFields();
}


public List<Map<Object,Object>> getData() {
String query = 'SELECT ';
List<String> fieldNames = new List<String>();


for(Schema.FieldSetMember f : getFields()){
query += f.getFieldPath() + ', ';
fieldNames.add(f.getFieldPath());
}
query += 'Id, Name FROM XYZ__c where Id=\'' + acctId + '\' LIMIT 1';


SObject myFieldResults = Database.Query(query);
Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();

This returns the error: "List has no rows for assignment to SObject". I'm pretty sure this is because of the part
where Id=\'' + acctId + '\' LIMIT 1';
I assume it isn't finding this because acctID doesn't exist in object XYZ. However, I'm not sure how to make the code display the correct data (that is associated with the account). Each record in XYZ has an associated account via look-up field, and I want to make sure that's the data that comes back. Any advice?

Thanks!

Hello,

I have a custom object (call it Object XYZ) and the normal Account object. I have a button that is supposed to draw information from fields in both Object XYZ and Account. The button is within Object XYZ.

Drawing info from fields in Object XYZ is no problem. For example:
xmldata += xmlField{!YIP__Object_XYZ__c.Name}
would extract all information within the 'Name' field in Object XYZ (with some minor tweaks).

However, I also want to try and draw info from fields in the Account object. I am having trouble. First I tried variations of
xmldata += xmlField{!YIP__Object_XYZ__c.Name.Account.Phone}
which I think was way off. Next I dug through the forums and tried
xmldata += xmlField{!YIP__Object_XYZ__c.YIP__Link__r.Phone}
where 'Link' is the name of the relationship between the two objects. Now I am stumped, mainly because other questions askers usually use a more traditional format (SELECT, WHERE, etc). Am I missing something obvious? Thanks


 Hi,

I am trying to create this graph in APEX. I am getting an error "Illegal assignment from LIST<Account> to LIST<XXX.Sample.RadarWedgeData>". Is this most likely because of a integer vs. number data type problem, a lack of data, or something else? Thanks
 

public class Sample {
    List<String> xx = new List<String> {'Planning','Management','Tax','Risk','Liability'};
    
    public class RadarWedgeData {
public Integer data1 { get; set; }
public Integer data2 { get; set; }
public Integer data3 { get; set; }


public RadarWedgeData(Integer data1 , Integer data2,Integer data3) {
this.data1 = data1;
this.data2 = data2;
this.data3 = data3;
}
}
    
    public List<RadarWedgeData> getData(){
          List<RadarWedgeData> memList = new List<RadarWedgeData>();
           memList = [SELECT test1__c, test2__c, test3__c from Account where ID = '001F0000018glHz'];
           for (Account mem: memList){              
               data.add(new RadarWedgeData(mem.test1__c, mem.test2__c, mem.test3__C));
        }
}
}


 

Hi all,

I am attempting to build a radar chart based off of this (https://github.com/developerforce/Visualforce-Charting-Examples" rel="nofollow) github page :

I've created the Account field set and included my three test variables in the field set. I've barely touched the base code yet, but I'm getting an error message when trying to preview the page. "System.QueryException: invalid ID field: null. Class.XXX.RadarChartController.getData: line 28, column 1"

Apex page code:

<apex:page standardController="Account" extensions="RadarChartController">  
<style>
    #vfext4-ext-gen1026 {
        width:800px !important;
    }
</style>  

<apex:chart name="myChart" height="600" width="650" legend="false" data="{!data}">
            <apex:legend position="left" />
            <apex:axis type="Radial" position="radial"/>
            <apex:radarSeries title="Customer Satisfaction" xField="field" yField="value" tips="true" opacity="0.4"/>
      </apex:chart>
</apex:page


Apex class code


public class RadarChartController {
public List<Map<Object,Object>> data = new List<Map<Object,Object>>();
public String acctId {get;set;}


public RadarChartController(ApexPages.StandardController controller){
    acctId = controller.getRecord().Id; //'001x00000035SrC';
}


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


public List<Map<Object,Object>> getData() {
    String query = 'SELECT ';
    List<String> fieldNames = new List<String>();


    for(Schema.FieldSetMember f : getFields()){
        query += f.getFieldPath() + ', ';
        fieldNames.add(f.getFieldPath());
    }
    query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1';


    SObject myFieldResults = Database.Query(query);
    Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
    Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();


    //creates a map of labels and api names
    Map<String,String> labelNameMap = new Map<String,String>();
    for(String key : fieldMap.keySet()){
         labelNameMap.put(fieldMap.get(key).getDescribe().getName(), fieldMap.get(key).getDescribe().getlabel());
    }


    //creates a map of labels and values
    for(String f : fieldNames){
        String fieldLabel = labelNameMap.get(f);
        String fieldValue = String.valueOf(myFieldResults.get(f));


        Map<Object, Object> m = new Map<Object,Object>();
        m.put('field', fieldLabel);
        m.put('value', fieldValue);
        data.add(m);
    }


    return data;
}
}


Never done much in Apex before, and this has me stuck. I changed line 25 in the controller code to make the query look for a specific account ID, but that didn't fix the problem. Any ideas?

Thanks!

Hey, I was wondering if there is a way to view all custom fields, fieldsets, validations rules, and so on I have created in my org.
I have an Apex class that creates a graph based off of a fieldset. It originally pulled from an Account fieldset (let's say the fieldset is called TestFieldSet). Here is relevant code:

public RadarChartController(ApexPages.StandardController controller){
acctId = controller.getRecord().Id;
}


public List<Schema.FieldSetMember> getFields() {
system.debug(SObjectType.Account.FieldSets.TestFieldSet.getFields());
return SObjectType.Account.FieldSets.TestFieldSet.getFields();
}


public List<Map<Object,Object>> getData() {
String query = 'SELECT ';
List<String> fieldNames = new List<String>();


for(Schema.FieldSetMember f : getFields()){
query += f.getFieldPath() + ', ';
fieldNames.add(f.getFieldPath());
}
query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1';


SObject myFieldResults = Database.Query(query);
Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();

However, I now want to pull a fieldset from another object. Call this TestFieldSet2. It is in custom object XYZ. However, the graph will still be displayed on an account record, so it needs to be associated with account ID in some way. I tried this code. Changes highlighted:

public RadarChartController(ApexPages.StandardController controller){
acctId = controller.getRecord().Id;
}


public List<Schema.FieldSetMember> getFields() {
system.debug(SObjectType.XYZ__c.FieldSets.TestFieldSet.getFields());
return SObjectType.XYZ__c.FieldSets.TestFieldSet.getFields();
}


public List<Map<Object,Object>> getData() {
String query = 'SELECT ';
List<String> fieldNames = new List<String>();


for(Schema.FieldSetMember f : getFields()){
query += f.getFieldPath() + ', ';
fieldNames.add(f.getFieldPath());
}
query += 'Id, Name FROM XYZ__c where Id=\'' + acctId + '\' LIMIT 1';


SObject myFieldResults = Database.Query(query);
Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();

This returns the error: "List has no rows for assignment to SObject". I'm pretty sure this is because of the part
where Id=\'' + acctId + '\' LIMIT 1';
I assume it isn't finding this because acctID doesn't exist in object XYZ. However, I'm not sure how to make the code display the correct data (that is associated with the account). Each record in XYZ has an associated account via look-up field, and I want to make sure that's the data that comes back. Any advice?

Thanks!

Hello,

I have a custom object (call it Object XYZ) and the normal Account object. I have a button that is supposed to draw information from fields in both Object XYZ and Account. The button is within Object XYZ.

Drawing info from fields in Object XYZ is no problem. For example:
xmldata += xmlField{!YIP__Object_XYZ__c.Name}
would extract all information within the 'Name' field in Object XYZ (with some minor tweaks).

However, I also want to try and draw info from fields in the Account object. I am having trouble. First I tried variations of
xmldata += xmlField{!YIP__Object_XYZ__c.Name.Account.Phone}
which I think was way off. Next I dug through the forums and tried
xmldata += xmlField{!YIP__Object_XYZ__c.YIP__Link__r.Phone}
where 'Link' is the name of the relationship between the two objects. Now I am stumped, mainly because other questions askers usually use a more traditional format (SELECT, WHERE, etc). Am I missing something obvious? Thanks


 

Hi all,

I am attempting to build a radar chart based off of this (https://github.com/developerforce/Visualforce-Charting-Examples" rel="nofollow) github page :

I've created the Account field set and included my three test variables in the field set. I've barely touched the base code yet, but I'm getting an error message when trying to preview the page. "System.QueryException: invalid ID field: null. Class.XXX.RadarChartController.getData: line 28, column 1"

Apex page code:

<apex:page standardController="Account" extensions="RadarChartController">  
<style>
    #vfext4-ext-gen1026 {
        width:800px !important;
    }
</style>  

<apex:chart name="myChart" height="600" width="650" legend="false" data="{!data}">
            <apex:legend position="left" />
            <apex:axis type="Radial" position="radial"/>
            <apex:radarSeries title="Customer Satisfaction" xField="field" yField="value" tips="true" opacity="0.4"/>
      </apex:chart>
</apex:page


Apex class code


public class RadarChartController {
public List<Map<Object,Object>> data = new List<Map<Object,Object>>();
public String acctId {get;set;}


public RadarChartController(ApexPages.StandardController controller){
    acctId = controller.getRecord().Id; //'001x00000035SrC';
}


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


public List<Map<Object,Object>> getData() {
    String query = 'SELECT ';
    List<String> fieldNames = new List<String>();


    for(Schema.FieldSetMember f : getFields()){
        query += f.getFieldPath() + ', ';
        fieldNames.add(f.getFieldPath());
    }
    query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1';


    SObject myFieldResults = Database.Query(query);
    Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
    Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();


    //creates a map of labels and api names
    Map<String,String> labelNameMap = new Map<String,String>();
    for(String key : fieldMap.keySet()){
         labelNameMap.put(fieldMap.get(key).getDescribe().getName(), fieldMap.get(key).getDescribe().getlabel());
    }


    //creates a map of labels and values
    for(String f : fieldNames){
        String fieldLabel = labelNameMap.get(f);
        String fieldValue = String.valueOf(myFieldResults.get(f));


        Map<Object, Object> m = new Map<Object,Object>();
        m.put('field', fieldLabel);
        m.put('value', fieldValue);
        data.add(m);
    }


    return data;
}
}


Never done much in Apex before, and this has me stuck. I changed line 25 in the controller code to make the query look for a specific account ID, but that didn't fix the problem. Any ideas?

Thanks!