• Varun Teja
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 26
    Replies
Can you please help on below criteria.

1) A picklist showing values 2011, 2012 and 2013
2) 2 Date fields (From Date and To Date)
3) When user picks the value in 1st picklist, From and To Date should automatically populate.
Ex: If I select 2011, From Date should be 01/01/2011 and End ddate should be 12/31/2011 automatically populate
If I select 2012, From Date should be 01/01/2012 and End ddate should be 12/31/2012 automatically populate

I have picklist as Year__c

Below formula has been given in From Date filed.

CASE(Year__c, 
2011 , DATE(2011,01,01) , 
2012, DATE(2012,01,01),
DATE(2013,01,01)


Getting error as "Error: Field Year__c may not be used in this type of formula"

Thanks In Advance
Can you please help on below criteria.

1) A picklist showing values 2011, 2012 and 2013
2) 2 Date fields (From Date and To Date)
3) When user picks the value in 1st picklist, From and To Date should automatically populate.
Ex: If I select 2011, From Date should be 01/01/2011 and End ddate should be 12/31/2011 automatically populate
If I select 2012, From Date should be 01/01/2012 and End ddate should be 12/31/2012 automatically populate

Thanks In Advance
Plase help me on test class.Thanks in advance



public class AccountSubmitPageController {
    
    public Account acount{get; set;}
    public Contact contct{get; set;}
    public Opportunity oportunity{get; set;}
    public Case casse{get; set;}

    public List<Contact> contactList{get; set;}
    public List<Opportunity> OppoList{get; set;}
    public boolean disableContact{get; set;}
    public boolean disableOpportunity{get; set;}
    
    public AccountSubmitPageController(ApexPages.standardController controller){  
        acount = new Account();
        contct = new Contact();
        oportunity= new Opportunity();
        casse=new Case();
        contactList=new List<Contact>();
        OppoList=new List<Opportunity>();
        disableContact=false;
        
    }


    public PageReference save() {
        //System.debug('------ Account----'+acount);
        insert acount;
        PageReference bp = new PageReference('/apex/ContactSubmitPage');
        bp.setRedirect(false);
        return bp;
        
    }
    
    public PageReference addMoreContacts() {
        contct.AccountId=acount.Id;
        if (!contactList.contains(contct)) {
             contactList.add(contct);
        }
        contct=new Contact();
        disableContact=true;
        PageReference pageref = new PageReference('/apex/ContactSubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
    
    public PageReference dontWantContact() {
        PageReference bp = new PageReference('/apex/OpportunitySubmitPage');
        bp.setRedirect(false);
        return bp;
    }
    public PageReference submitContact() {
        contct.AccountId=acount.Id;
        if (!contactList.contains(contct)) {
            contactList.add(contct);
        }
        if(contactList.size()>0){
            //System.debug('------ contactList----'+contactList);
            insert contactList;
        }
        
        PageReference pr = new PageReference('/apex/OpportunitySubmitPage');
        pr.setRedirect(false);
        return pr;
        
    }
    
    public PageReference addMoreOpportunities() {
        
        oportunity.AccountId=acount.Id;

        if (!OppoList.contains(oportunity)) {
            OppoList.add(oportunity);
        }
        oportunity=new Opportunity();
        disableOpportunity=true;
        PageReference pageref = new PageReference('/apex/OpportunitySubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
    
       public PageReference dontWantOpportunity() {
        PageReference bp = new PageReference('/apex/CaseSubmitPage');
        bp.setRedirect(false);
        return bp;
    }
    
    public PageReference submitOpportunity() {
        oportunity.AccountId=acount.Id;
        if (!OppoList.contains(oportunity)) {
            OppoList.add(oportunity);
        }
        if(OppoList.size()>0){
            //System.debug('------ OppoList----'+OppoList);
            insert OppoList;
        }
        PageReference pr = new PageReference('/apex/CaseSubmitPage');
        pr.setRedirect(false);
        return pr;
    }
    
    public PageReference caseConfirm() {
        casse.AccountId=acount.Id;
        insert casse;
        Case cs=[select Id,CaseNumber from Case where AccountId=:acount.Id];
        //System.debug('------ casse.CaseNumber----'+cs.CaseNumber);
        //System.debug('------ casse.CaseId----'+cs.Id);
        PageReference pr = new PageReference('/apex/ListAllSubmitPage?caseNumbr='+cs.CaseNumber+'&caseIds='+cs.Id);
        pr.setRedirect(false);
        return pr;
    }
    
        public PageReference done() {
        acount = new Account();
        PageReference pageref = new PageReference('/apex/AccountSubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
    
        public PageReference nextToOpportunity() {
        PageReference bp = new PageReference('/apex/OpportunitySubmitPage');
        bp.setRedirect(false);
        return bp;
    }
    
           public PageReference nextToCase() {
        PageReference bp = new PageReference('/apex/CaseSubmitPage');
        bp.setRedirect(false);
        return bp;
    }
        public PageReference backToContact() {
        PageReference bp = new PageReference('/apex/ContactSubmitPage');
        bp.setRedirect(false);
        return bp;
    }
 }
I'm trying to save account name to contact in VF page 2 which is saved account in VF page1.I count not able to save account name into contact. But contact is saving without account name.Please help me on this
Below is my code:

VF page1:
<apex:page standardController="Account" extensions="AccountSubmitPageController">
    <apex:form >
        <apex:pageBlock title="Insert Account  Record" id="pbAccountDetails">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:inputField value="{! Account.OwnerId }" />
                <apex:inputField value="{! Account.Name }" />
                <apex:inputField value="{! Account.Type }" />
                <apex:inputField value="{! Account.Industry }" />
                <apex:inputField value="{! Account.AnnualRevenue }" />
                <apex:inputField value="{! Account.NumberOfEmployees }" />
                <apex:inputField value="{! Account.Phone }" />
                <apex:inputField value="{! Account.Rating }" />
                <center><apex:commandButton action="{! save }" value="Save" /></center>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

VF page 2:

<apex:page standardController="Contact" extensions="AccountSubmitPageController">
    <apex:form >
        <apex:pageBlock title="Insert Contact  Record">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:outputText label="Account Name" value="{!$CurrentPage.parameters.accountName}" />
                <apex:inputField value="{! Contact.FirstName }" />
                <apex:inputField value="{! Contact.LastName }" />
                <apex:inputField value="{! Contact.Birthdate }" />
                <apex:inputField value="{! Contact.Description }" />
                <apex:inputField value="{! Contact.Email }" />
                <apex:inputField value="{! Contact.HomePhone }" />
                <apex:inputField value="{! Contact.Level__c }" />
                <apex:inputField id="total" value="{!Contact.Total_Contacts_Added_till_Now__c}" />
                
            </apex:pageBlockSection>
            <apex:pageblockButtons location="bottom">
                <apex:commandButton style="float:centre" action="{! addMoreContacts }" value="Add More Contacts" />
                <apex:commandButton style="float:centre" value="I don't want to create contact" />
                <apex:commandButton style="float:centre" value="Submit Contact's" />
            </apex:pageblockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller class:

 
global class AccountContactCaseOpporBatch implements Database.Batchable<sObject> {
     global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT ID, Name, Archival_Number_Of_Cases_Count__c, Archival_Number_Of_Contacts_Count__c, Archival_Number_Of_Oppt_Count__c,'+
            '(SELECT ID, Name, CreatedDate FROM Contacts Where CreatedDate <= LAST_N_DAYS:5),'+
            '(SELECT ID, Name, CreatedDate FROM Opportunities Where CreatedDate <= LAST_N_DAYS:5 ),'+
            '(SELECT ID, CaseNumber, CreatedDate FROM Cases Where CreatedDate <= LAST_N_DAYS:5) FROM Account'
        );
    }
    
    global void execute(Database.BatchableContext bc, List<Account> scope){
        List<Account> accounts = new List<Account>();
        List<Contact> contacts = new List<Contact>();
        List<Opportunity> opportunities = new List<Opportunity>();
        List<Case> cases = new List<Case>();
        List<ArchivalTable__c> archivTableList = new List<ArchivalTable__c>();
        
        for (Account accou : scope) {
             Integer contactProcessed = 0;
             Integer opportunityProcessed = 0;
             Integer caseProcessed = 0;

            for (Contact contct : accou.contacts) {
                //System.debug(' List of Contact Records ---'+contct);
                contacts.add(contct);
                contactProcessed = contactProcessed + 1;
            }
            for (Opportunity opport : accou.opportunities) {
                //System.debug(' List of Opportunity Records ---'+opport);
                opportunities.add(opport);
                opportunityProcessed = opportunityProcessed + 1;
            }
            for (Case cas : accou.cases) {
                //System.debug(' List of Case Records ---'+cas);
                cases.add(cas);
                caseProcessed = caseProcessed + 1;
            }
            
            if (accou.Archival_Number_Of_Cases_Count__c==null || accou.Archival_Number_Of_Cases_Count__c==0) {
                accou.Archival_Number_Of_Cases_Count__c = caseProcessed;
            }else {
                accou.Archival_Number_Of_Cases_Count__c = accou.Archival_Number_Of_Cases_Count__c + caseProcessed;
            }
            
            if (accou.Archival_Number_Of_Contacts_Count__c==null || accou.Archival_Number_Of_Contacts_Count__c==0) {
                accou.Archival_Number_Of_Contacts_Count__c = contactProcessed;
            }else {
                accou.Archival_Number_Of_Contacts_Count__c = accou.Archival_Number_Of_Contacts_Count__c + contactProcessed;
            }
            
            if (accou.Archival_Number_Of_Oppt_Count__c==null || accou.Archival_Number_Of_Oppt_Count__c==0) {
                accou.Archival_Number_Of_Oppt_Count__c = opportunityProcessed;
            }else {
                accou.Archival_Number_Of_Oppt_Count__c = accou.Archival_Number_Of_Oppt_Count__c + opportunityProcessed;
            }
            
            accounts.add(accou);
            
               //System.debug(' List of Accounts  Records ---'+accounts);
               System.debug('Account Name  '+accou.Name);
            
                ArchivalTable__c archieveData = new ArchivalTable__c();
                archieveData.ArchivalAccount__c = String.valueOf(accou.Id); 
                
                 System.debug('archieveData.ArchivalAccount__c--  '+archieveData.ArchivalAccount__c);
                    archieveData.Number_Of_Contacts_Count__c = contactProcessed;
           
                //System.debug('archieveData.Number_Of_Contacts_Count__c--  '+archieveData.Number_Of_Contacts_Count__c);

                    archieveData.Number_Of_Oppt_Count__c = opportunityProcessed;

                //System.debug('archieveData.Number_Of_Oppt_Count__c--  '+archieveData.Number_Of_Oppt_Count__c);

                    archieveData.Number_Of_Cases_Count__c = caseProcessed;

               //System.debug('archieveData.Number_Of_Cases_Count__c--  '+archieveData.Number_Of_Cases_Count__c);
                archieveData.Date__c = Date.today();
                
                archivTableList.add(archieveData);
            //System.debug('------archivTableList--  '+archivTableList);
         
        }
        
        if(cases.size()>0){
        delete cases;
        }
       
        if(contacts.size()>0){
        delete contacts;
        }
        if(opportunities.size()>0){
        delete opportunities;
        }
        
        if(archivTableList.size()>0){
        insert archivTableList;
        } 

        if(accounts.size()>0){
        update accounts;
        }
    } 

    global void finish(Database.BatchableContext bc){
        
        
        System.debug(' Records processed --- '+bc.getJobId());
        AsyncApexJob result = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {result.CreatedBy.Email};
            mail.setToAddresses(toAddresses);
        mail.setSubject('Status of Contacts,opportunities and cases batch job -- ' + result.Status);
        mail.setPlainTextBody
            ('The batch Apex job processed ' + result.TotalJobItems +
             ' batches with '+ result.NumberOfErrors + ' failures.');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    } 
}

Thanks in Advance
I'm new to slaesforce.I want to create test class for my below code:

public class AccountContOpptCheckBoxController {
    
    public List<Account> acctList{get;set;}
    public List<Contact> conList{get;set;}
    public List<Opportunity> oppList{get;set;}
    public List<ContactWrapper> conWrList{get;set;}
    public List<OpportunityWrapper> opportList{get;set;}
    public List<Contact> selectedContacts{get;set;}
    public List<Opportunity> selectedOpportunities{get;set;}
    //public List<StoreAccountData__c> storeList{get;set;}
    public List<StoreAccountData__c> storedList= new List<StoreAccountData__c>();
     
    Set<ID> acctIds = new Set<ID>();
    
    public AccountContOpptCheckBoxController(ApexPages.standardController controller){  
        getAccountDetails();
        for(Account ac: acctList){ 
            if(ac.Id != null){
                acctIds.add(ac.Id);
            } 
        }
    }
    
    public List<Account> getAccountDetails() {    
           acctList = Database.query('SELECT Name FROM Account LIMIT 1');
        return acctList;
 }
    
    public PageReference reset() {
        
       PageReference newpage = new PageReference(System.currentPageReference().getURL());   
   newpage.getParameters().clear();
   newpage.setRedirect(true);
   return newpage;
        
    }
    
    public class ContactWrapper {
     public boolean cb {get;set;}
     public Contact contct {get;set;}

     public ContactWrapper(Contact contct){
          cb=false;
          this.contct = contct;
     }
}
    
    public class OpportunityWrapper {
     public boolean cbOp {get;set;}
     public Opportunity oppornty {get;set;}

     public OpportunityWrapper(Opportunity oppornty){
          cbOp=false;
          this.oppornty = oppornty;
     }
}
    
    public Pagereference getContacts() {
        if(conWrList == null) {
            conWrList = new List<ContactWrapper>();
            for(Contact c : [select id,name,phone,accountId from contact where accountid in : acctIds]) {
                conWrList.add(new ContactWrapper(c));
            }
        }
        return NULL;
    }
    
        public Pagereference getOpportunitiess() {
        if(opportList == null) {
            opportList = new List<OpportunityWrapper>();
            for(Opportunity p : [select id,name,StageName,AccountId from Opportunity where accountid in : acctIds]) {
                opportList.add(new OpportunityWrapper(p));
            }
        }
        return NULL;
    }
    
    public List<Contact> getSelectContactDetails()
    {
        selectedContacts = new List<Contact>();
        if(conWrList!=null){
            for(ContactWrapper cCon : conWrList) {
                if(cCon.cb == true) {
                    selectedContacts.add(cCon.contct);
                }
            }
        }
        return selectedContacts;
    }
    
    public List<Opportunity> getSelectOpporDetails()
    {
        selectedOpportunities = new List<Opportunity>();
        if(opportList!=NULL){
            for(OpportunityWrapper Opt : opportList) {
                if(Opt.cbOp == true) {
                    selectedOpportunities.add(Opt.oppornty);
                }
            }
        }
        return selectedOpportunities;
    }
    
    public PageReference submit() {
        PageReference np = new PageReference('/apex/FetchAcctContactOpprCheckboxPage');
        np.setRedirect(false);
        return np;
    }
     public PageReference back() {
        PageReference bp = new PageReference('/apex/AccountContOpptCheckboxPage');
        bp.setRedirect(false);
        return bp;
    }
    
    public PageReference confirm() {
        
        List<StoreAccountData__c> storeList= new List<StoreAccountData__c>();
        
        if(selectedContacts!=null){
            for(Contact ct:selectedContacts){
                StoreAccountData__c sd= new StoreAccountData__c();
                //ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Select Name--'+ct.AccountId));
                sd.AccountStore__c=ct.AccountId;
                sd.Name=ct.Name;
                sd.Phone__c=ct.Phone;
                storeList.add(sd);
            }
        }
        
        if(selectedOpportunities!=null){
             for(Opportunity op:selectedOpportunities){
                StoreAccountData__c sd1= new StoreAccountData__c();
                sd1.AccountStore__c=op.AccountId;
                sd1.OppName__c=op.Name;
                sd1.StageName__c=op.StageName;
                storeList.add(sd1);
            }
        }
        insert storeList;     
        ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Records added successfully'));
        return NULL;
    }
}