• Richa_Learning
  • NEWBIE
  • 135 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 88
    Replies
Hi,
I am new to Apex and SOQL. I tried creating the nested query in workbench and it works fine and return 80K rows. Below is the query
SELECT ID,name,region__c, tracker__c,
(select id,Account__r.name,product__c from product_account__r),
(select year__c from product_year__r)
FROM tracker__c
My issue is how do I export this in excel or csv. I read blog and it was mentioned that we need to write a code. Could someone please help me here.
I want to export the data to excel or csv that is coming from this query.(80K rows)

Thanks.
 
Hello All,

I have been trying this from last week but I am not getting anywhere.
 
Requirement à
 
1) send report of all records in one email  to each  record owner 30 days before the Target month if A ,B, C,  D fields are blank.
 
Target month is a single picklist value from January – December. We always assume that Target month will be 1st of every month. Example: If Target= July i.e. 1st July 2017 and email should go 30 days before. If user puts Target month in Mid-June as July then email should go at the same time as it is less than 30 days.
 
2) after email has been sent in current year for that record then email should go next year based on the Target month like above if A ,B, C,  D fields are blank.
 
Please help.
Hi,

I need to create a VF email template in Salesforce and need to refer opportunity line items. I have custom object training__C that has a lookup with Opportunity object.

How can I refer Opportunity line items from training__C object?

Thanks for your help.
Hi,
I have created a field sets for Account that has A,B, C,D,E,F as fields.  When i add the field set on Vf page it comes as column 2 as i have specified it. But i need D and E field should come in column 1.
 
<apex:page standardController="Account" extensions="CloneAccountController">



    <apex:sectionHeader title="Account Edit" />
  <apex:form id="frmId">
        <apex:pageBlock title="Account Edit" mode="edit">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Account Information"  columns="2" >
            <apex:repeat value="{!$Objecttype.Account.fieldsets.Method}" var="AI">
              
            <apex:inputField value="{!objaccount[AI.fieldPath]}" required="{!OR(AI.required, AI.dbrequired)}"/>  
            </apex:repeat>
        </apex:pageBlockSection>
        
        
        
        </apex:pageBlock>
</apex:form>
</apex:page>



How to do that?
Hi,
I have create a field sets for Account that has A,B, C,D as fields.  I have 2 record type for Account. A,B is required for 1 record type and C,D is require for another record type. IF i mark them as Require on the fieldset property then all fields are required for both page layout.

How to make sure that they are required on the relevant page layout?
<apex:page standardController="Account" extensions="CloneAccountController">



    <apex:sectionHeader title="Account Edit" />
  <apex:form id="frmId">
        <apex:pageBlock title="Account Edit" mode="edit">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Account Information"  columns="2" >
            <apex:repeat value="{!$Objecttype.Account.fieldsets.Method}" var="AI">
              
            <apex:inputField value="{!objcase[AI.fieldPath]}" required="{!OR(AI.required, AI.dbrequired)}"/>  
            </apex:repeat>
        </apex:pageBlockSection>
        
        
        
        </apex:pageBlock>
</apex:form>
</apex:page>

 
Hi,

I created a custom button that should redirect to different apex page based on the record type.
Example: If record type = a then it should redirect to "abc" page otherwise "xyz" page

But when i click on the button i get illiegal token error.
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var rtype;

if({!Account.RecordTypeId} == "012G0000000nKI7")
{
rtype = "/apex/Newcase?";
}
else 
{
    rtype = "/apex/oldcase?";

}

window.top.location.href = rtype ;

Please help.
 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"
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
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)
 
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!
hi,
I am populating few fields on account when i click new custom button. I am using url hack to populate th fields.  Button is copying the value for all fields except text area.

I want to copy description field value to another record.

I can see value in the url is copid but it is not populated on the field. How can i copy text area field using url hack?
/001/e?retURL=/{!Account.Id}

&CF00N63000000HV70={!Account.Description__c}

 
All,

I have logic on my controller that it should clone few fields only.....I want to clone only those fields that are not in cloneaccount custom settings...below controller clones everything .............

Also, we have workflow rules that sends out an email as soon as record is created..i want email to only go out when i hit save.....not when i hit clone.....

Please let me know what's wrong with the below controller:
public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
      set<String> setExFields = new set<String>();
    private Account objNewAccount;
     Map<String, Schema.SObjectField> mapAccountFields;
    
    public AccountController(ApexPages.StandardController controller) 
    {
      
     }
               
              public PageReference autoRun()
 {
        AccountID = ApexPages.currentPage().getParameters().get('id');
                
        if(AccountID != null)

        {        mapAccountFields = Schema.SObjectType.Account.fields.getMap() ;
		
		
		
		List<CloneAccount__c > Exfields = Cloneaccount__c.getall().values();
                 
            for( Cloneaccount__c excludedField: ExFields){
                setExFields.add(excludedField.Name.toLowerCase());
            }
          
            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);

        //     insert objaccount;

       PageReference cloneaccount = new PageReference('/'+objaccount.id+'/e?clone=1');
        cloneaccount.setRedirect(true);
        return accountPage;
    }
return null;
}

}

 
Hi All,

I am creating a custom clone button on account. this is my VF page and controller. Button works fine but the issue is :

we have workflow rules that send an email as soon as record is created...when i hit clone the email is triggered...and when i hit save  the email goes out again...I want email to go out only when i hit save.....please help
 
<apex:page standardController="Account" extensions="AccountController" action="{!autoRun}">

  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have 
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>
public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
   
    private Account objNewAccount;
     Map<String, Schema.SObjectField> mapAccountFields;
    
    public AccountController(ApexPages.StandardController controller) 
    {
      
     }
               
              public PageReference autoRun()
 {
        AccountID = ApexPages.currentPage().getParameters().get('id');
                
        if(AccountID != null)

        {        mapAccountFields = Schema.SObjectType.Account.fields.getMap() ;

                objNewAccount = [ select id,OwnerId,AccountId,Status__c from Account where id = :AccountID ] ;

                objAccount = objNewAccount.Account(false,true,false,false);

             insert objaccount;

       PageReference cloneaccount = new PageReference('/'+accountid+'/e?clone=1');
        cloneaccount.setRedirect(true);
        return accountPage;
    }
return null;
}

}

 
Hi All,

I am creating a custom clone button on account. this is my VF page and controller. Button works fine but the issue is :
when i click clone the new record is created and saved.  I want when i click clone the page should remain in edit form and i should save it manually.

Please help.
 
<apex:page standardController="Account" extensions="AccountController" action="{!autoRun}">

  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have 
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>

Here is my controller:
public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
   
    private Account objNewAccount;
     Map<String, Schema.SObjectField> mapAccountFields;
    
    public AccountController(ApexPages.StandardController controller) 
    {
      
     }
               
              public PageReference autoRun()
 {
        AccountID = ApexPages.currentPage().getParameters().get('id');
                
        if(AccountID != null)

        {        mapAccountFields = Schema.SObjectType.Account.fields.getMap() ;

                objNewAccount = [ select id,OwnerId,AccountId,Status__c from Account where id = :AccountID ] ;

                objAccount = objNewAccount.Account(false,true,false,false);

             insert objaccount;

        return new PageReference('/'+objAccount.id);
    }
return null;
}

}

 
Hi All,

I am trying to add a custom clone buon on Account. Here is my page:
 
<apex:page standardController="Account" extensions="AccountController" action="{!autoRun}">

  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have 
      been redirected back to the record you clicked the button from.
  </apex:outputPanel>
</apex:page>

Here is my controller:
 
public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
   
    private Account objNewAccount;
     Map<String, Schema.SObjectField> mapAccountFields;
    
    public AccountController(ApexPages.StandardController controller) 
    {
      
     }
               
              public PageReference autoRun() {
        AccountID = ApexPages.currentPage().getParameters().get('id');
                
        if(AccountID != null)

        {        mapAccountFields = Schema.SObjectType.Account.fields.getMap() ;

                objNewAccount = [ select id,OwnerId,AccountId,Status__c from Account where id = :AccountID ] ;

                objAccount = objNewAccount.Account(false,true,false,false);

        }  
        return null;
    }
               
    public PageReference save()
    {
        insert objAccount;
        
        return new PageReference('/'+objAccount.id);
    }
}

When i click on clone buton on account i get the VF page error:
You tried calling Apex Code from a button.  If you see this page, something went wrong.  You should have 
      been redirected back to the record you clicked the button from.

Could you please help. I am not sure what is wrong in the code.

Thanks
 
Hi,

We uses share activiities that means we can add multiple contacts to an event. Stndar relate list "Name" only shows contact name an the type. So i am trying to add aVF page on event to show the contacts associated to an event and their email address.

I am getting this error:
Could not resolve field 'eventwhoids' from <apex:outputField> value binding '{!Event.eventwhoids}' in page Events

this is my page:
 
<apex:page standardController="Event" >
    <apex:pageBlock>
        <apex:pageBlockSection title="Contacts">
           
            <apex:outputField value="{!Event.Eventwhoids}"/>

                </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

thanks.
Richa
Hi,

I am trying to add one Vf page on another Vf page. this is my page. 
<apex:page standardController="Account" extensions="Accountsextension" >
   
  
      
      <apex:pageBlock title="Account History" id="Account_History">
      <apex:pageBlockTable value="{!acchistlist}" var="accounthistory" rows="1000">
         <apex:column value="{!accounthistory.createddate}"/>
         <apex:column value="{!accounthistory.createdby.name}"/>
         <apex:column value="{!accountHistory.field}"/>
         <apex:column value="{!accounthistory.oldvalue}"/>
         <apex:column value="{!accounthistory.newvalue}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
    
    
    
</apex:page>

 i want to add another VF page called "Value" on this with this size

Height (pixels): 50
Width(pixels): 100%

Please help.



 
Hi,

our developer has created this trigger to check the owner of an account. Initialowner__C is a cusotm field and a text field. I searched everywhere but i am not sure from where we can get the initialowner__C field value.

Any idea?
trigger ownerchange on Account (before insert) {
Account [] acc = Trigger.new.clone();
Profile pfs = [Select Id, name from Profile where id = :UserInfo.getProfileId()];
UserRole rls = null;
if(UserInfo.getUserRoleId() != null) {
rls = [Select Id, name from UserRole where id =:UserInfo.getUserRoleId() ];
} 
if(acc[0].InitialOwner__c!=null && ((rls != null && rls.name == 'Team') || pfs.name =='Manager')) {
Trigger.new[0].Ownerid = Trigger.new[0].InitialOwner__c;

} 


}

 
Hi,

I am trying to add a validation rule in trigger that if

Details status = 'In Progress" then Tracker status cannot be updated to Closed.

I get this error "Comparison arguments must be compatible types: Schema.SObjectField​"
 
trigger Tracker_AfterUpdate on Tracker__c (After Update) 
{   
       
        if(Trigger.IsAfter && Trigger.IsUpdate)
        {           
            Set<Id> TrackerIDs = new set<Id>();   
                        
            for(Tracker__c Tempdata : trigger.new)
            {                 
                if(Tempdata.Status__c=='Closed' && details__c.status__c=='In progress')
                {
                Tempdata.Status__c.adderror ('not allowed');
                }                        
            }           
                      
        }
    }

Please help
Hi,
I have this VF page for Custom object (invoice__c). User when they post comment it display the date, comments and who posted it. it shows like this from column (A to C). We woul like capture another field "Assigned To" (column D)  on this page. So when user write comments they assigned it to some other users.

User-added image

"Assgined To " is on the parent object (invoice__c) but i want to capture on child page too (invoice_detail__c)..here is my controller:
 
public with sharing class invoicedetails
{       
     Private final Id InvoiceId;
    
    public invoice_detail__c invoicedetail {get; set;}
   
      public invoice__c invoice {get; set;}
        
    public list<Invoice_detail__c> details
    {
        get
        {
            try
            {   
                string sRecordid=String.escapeSingleQuotes(InvoiceId);  
                
                list<Invoice_detail__c> tempdata = new list<Invoice_detail__c>();
				
                
                
                    tempdata = [select Date__c, Text__c ,createdbyid from Invoice_detail__c where Invoice__c=:InvoiceId order by Response_Date__c desc limit 50000];
                    
                    system.debug('\n----'+tempdata);    
		
                          
                return tempdata;
            }
            catch(exception ex)
            {
                return new list<Invoice_detail__c> ();
                
            }
        }
    }
       
   
    public invoicedetails(ApexPages.StandardController controller)     
    {       
        try
        {
            InvoiceId = controller.getId();
           
            invoicedetail = new Invoice_detail__c();   
            invoice = new Invoice__c(); 
         
        }
                
    }
        
        public Pagereference saveResponse()
    {
        try
        {   
            String sRecordid=String.escapeSingleQuotes(InvoiceId);  
            
                      
            if((sRecordid.length() == 15 || sRecordid.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', sRecordid))
            {
                if(checkParticipants(sRecordid))
                {
                    invoicedetail.Invoice__c=InvoiceId;
            
                    //use for date and time(march release)
                     invoicedetail.Response_Date__c=Datetime.now();
                    system.debug('\n----invoicedetail--'+invoicedetail);
                    insert invoicedetail;
                   
                    invoice.id = InvoiceId;
                   
                   
                   
                    invoice = new Invoice__c();
                    
                    invoicedetail = new Invoice_detail__c();
                    PageReference CurrentPage = new PageReference('/'+InvoiceId);
                    CurrentPage.setRedirect(true);
                    return CurrentPage;                 
                }
                
            }
            return null;
        }
        
    }
   
 
}

Please help.
Hi All,

I have 2 custom object Invoicing and Invoice details. Invoice details has a lookup relationship to Invoice. this query works fine
[select Date__c,company__c  from invoicing_details_gen__c where invoicing__c=:invoiceId ];

but i need to query 1 field from invoicing__C object also. when i try this I get the below error:

Error: Compile Error: Didn't understand relationship 'Invoiving__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name
[select Date__c,company__c ,(select region__c from invoicing__c) from invoicing_details_gen__c where invoicing__c=:invoiceId ];
How can i query this?

Thanks,
Richa
 
Hi,

our developer has created this apex class on custom object (Invoice Client) so we can track field history tracking . On this object  when we change status__c field then history is captured. We want to track history for other fields too. What is the easiest way to inlcude other fields so we can track history on it?
public with sharing class invoice 
{       
    private final string sFieldHistoryTrackObjName = 'Invoice_client';
    private final string sFieldHistoryTrackFldName = 'Status__c';  
    
    
 
    public string sHistoryTrackObjectName
    {
        get
        {
            return sFieldHistoryTrackObjName;
        }
    
    }
   
    public List<string> HistoryTrackFieldName
    {
        get
        {
            
            return new string[]{sFieldHistoryTrackFldName};
        }
    
    } 
}

Thanks.
Richa
 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"
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
Hi,
I am new to Apex and SOQL. I tried creating the nested query in workbench and it works fine and return 80K rows. Below is the query
SELECT ID,name,region__c, tracker__c,
(select id,Account__r.name,product__c from product_account__r),
(select year__c from product_year__r)
FROM tracker__c
My issue is how do I export this in excel or csv. I read blog and it was mentioned that we need to write a code. Could someone please help me here.
I want to export the data to excel or csv that is coming from this query.(80K rows)

Thanks.
 
Hi,
I have create a field sets for Account that has A,B, C,D as fields.  I have 2 record type for Account. A,B is required for 1 record type and C,D is require for another record type. IF i mark them as Require on the fieldset property then all fields are required for both page layout.

How to make sure that they are required on the relevant page layout?
<apex:page standardController="Account" extensions="CloneAccountController">



    <apex:sectionHeader title="Account Edit" />
  <apex:form id="frmId">
        <apex:pageBlock title="Account Edit" mode="edit">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Account Information"  columns="2" >
            <apex:repeat value="{!$Objecttype.Account.fieldsets.Method}" var="AI">
              
            <apex:inputField value="{!objcase[AI.fieldPath]}" required="{!OR(AI.required, AI.dbrequired)}"/>  
            </apex:repeat>
        </apex:pageBlockSection>
        
        
        
        </apex:pageBlock>
</apex:form>
</apex:page>

 
 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"
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
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)
 
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!
All,

I have logic on my controller that it should clone few fields only.....I want to clone only those fields that are not in cloneaccount custom settings...below controller clones everything .............

Also, we have workflow rules that sends out an email as soon as record is created..i want email to only go out when i hit save.....not when i hit clone.....

Please let me know what's wrong with the below controller:
public with sharing class AccountController {

    public Account objAccount {get;set;}        
    public string AccountID;                        
      set<String> setExFields = new set<String>();
    private Account objNewAccount;
     Map<String, Schema.SObjectField> mapAccountFields;
    
    public AccountController(ApexPages.StandardController controller) 
    {
      
     }
               
              public PageReference autoRun()
 {
        AccountID = ApexPages.currentPage().getParameters().get('id');
                
        if(AccountID != null)

        {        mapAccountFields = Schema.SObjectType.Account.fields.getMap() ;
		
		
		
		List<CloneAccount__c > Exfields = Cloneaccount__c.getall().values();
                 
            for( Cloneaccount__c excludedField: ExFields){
                setExFields.add(excludedField.Name.toLowerCase());
            }
          
            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);

        //     insert objaccount;

       PageReference cloneaccount = new PageReference('/'+objaccount.id+'/e?clone=1');
        cloneaccount.setRedirect(true);
        return accountPage;
    }
return null;
}

}