You need to sign in to do that
Don't have an account?
Richa_Learning
Retrieve cusotm setting list field value
Hi,
I am using custom settings (Cloneaccounts__c ) to inlcude field API name so they shoud not be cloned. there are few fields where api name is more than 40 characters and i am not able to save them. I created a field "Fieldname" on custom settings (Cloneaccounts__c ) so i can save fields api name in it. But how do i modify this controller to read the value of CloneAccounts__c field "Fieldname"
Please help
I am using custom settings (Cloneaccounts__c ) to inlcude field API name so they shoud not be cloned. there are few fields where api name is more than 40 characters and i am not able to save them. I created a field "Fieldname" on custom settings (Cloneaccounts__c ) so i can save fields api name in it. But how do i modify this controller to read the value of CloneAccounts__c field "Fieldname"
public with sharing class CloneaccController { public account objaccount {get;set;} public string accountID; private account objNewaccount; private string queryString = ''; public string strPrevCurrency {get;set;} Map<String, Schema.SObjectField> mapaccountFields; set<String> setexfields = new set<String>(); public CloneaccController(ApexPages.StandardController controller) { accountID = ApexPages.currentPage().getParameters().get('id'); if(accountID != null) { mapaccountFields = Schema.SObjectType.account.fields.getMap() ; List<Cloneaccounts__c > lstexfields = Cloneaccounts__c.getall().values(); for( Cloneaccounts__c exfield: lstexfields){ setexfields.add(exfield.Name.toLoweraccount()); } for(String s: mapaccountFields.keyset()){ if(!setexfields.contains(s)){ if(queryString == ''){ queryString += s; }else{ queryString += ',' + s; } } } objnewaccount = Database.Query('Select ' + queryString + ' From account where id= \'' + String.escapeSingleQuotes(accountID) + '\''); objaccount = objNewaccount.clone(false,true,false,false); } } public PageReference save() { insert objaccount; return new PageReference('/'+objaccount.id); } }
Please help
Try this
All Answers
Can you try the below code in your controller.
private static Cloneaccounts__c sfParams = Cloneaccounts__c .getOrgDefaults();
Thanks,
BM
TO fit field names that are mroe than 40 characters long you can modify your Fieldname field type to text area
Initially i created a list with no field and enter the value directly using manage--> new .but there are some api names that i was not able to fit.
Now i created a field "fieldname__C" text area and i am entering the api names in it.
Issues is my controller is not reading the value of fieldname__c
then add that fields string to your query
issue is because you don't have a FieldName__c filled. so when you call exfield.FieldName__c its null and then you call toLoweraccount on a null object that throws an exception. Are you trying to do toLowerCase()
Try this