You need to sign in to do that
Don't have an account?

Apex Class not returning query data
Hi,
I am calling my VF page using button. This is my controller. When i click on the button , i want those fields to be copied(pre-populated) that are not in Cloneaccount__c (Custom settings).
But when i click on button it copying every field. Could you please help to copy only those fields that are not in Cloneaccount_c (custom settings)
Thanks so much!
I am calling my VF page using button. This is my controller. When i click on the button , i want those fields to be copied(pre-populated) that are not in Cloneaccount__c (Custom settings).
But when i click on button it copying every field. Could you please help to copy only those fields that are not in Cloneaccount_c (custom settings)
public class myClonedRecordEditPageController { private final Account o; private Account objNewAccount; Map<String, Schema.SObjectField> mapaccfields; set<String> setExfield = new set<String>(); private string qstr = ''; public myClonedRecordEditPageController(ApexPages.StandardController stdController) { this.o = (Account)stdController.getRecord(); } public PageReference autoRun() { String AccountID = ApexPages.currentPage().getParameters().get('id'); if (AccountID == null) { return null; } if(AccountID != null) { mapaccfields = Schema.SObjectType.Account.fields.getMap() ; List<Cloneaccount__c > Exfield = Cloneaccount__c.getall().values(); for( Cloneaccount__c excludedField: Exfield){ setExfield.add(excludedField.Name.toLowerAccount()); } for(String s: mapaccfields.keyset()){ if(!setExfield.contains(s)){ if(qstr == ''){ qstr += s; }else{ qstr += ',' + s; } } } objnewAccount = Database.Query('Select ' + qstr + ' From Account where id= \'' + String.escapeSingleQuotes(AccountID) + '\''); system.debug('hello'+ objnewAccount); PageReference pageRef = new PageReference('/' + AccountID+'/e'); pageRef.setRedirect(true); return pageRef; } return null; } }
Thanks so much!
Just try to debug set and map keyset and check if field present in both the collections are of same case i.e. either upper or lower.
I got your problem. In page reference method you are passing the Id of the existing account instead(not objnewaccount), which is why you are being redirected to the standard edit page of the Account.
This error is coming because your record is not saved yet and you are trying to redirect to the edit page of the record. I believe you want to clone the record. To do so, you will either have to create vf page or use the concept of url hacking.
Pankaj - as you suggested i did create a VF page and updated my class. I am using custom settings (Cloneaccounts__c ) to inlcude field API name to 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 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
Bind objNewAccount variable with the page instead of objaccount and on click of save button perform dml on objNewAccount variable.