• Nitesh Trivedi
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
controller
public QuoteTermEditorController(ApexPages.StandardSetController acon) {
        this.acon = acon;
        recordId = ApexPages.currentPage().getParameters().get('id');
        //system.debug(recordId);
        revertMap = new Map<Id,Quote_term__c>();
    }
    public List<Quote_term__c> getRecords(){
        if(recordId!=null){
        List<Quote_term__c> termExtract = [select id,name,print_order__c,Active__c,type__c,Standard_Term__c,body__c,Quote_del__r.name,(select id,type__c,name,Standard_Term__c,body__c,Locked__c from Quote_Terms1__r where Quote_del__c=:recordId and Active__c=true) from Quote_term__c where (Type__c='Standard' or Type__c='Custom') order by print_order__c asc];
        termList = new List<Quote_term__c>();
        for(Quote_term__c term:termExtract){
            if(term.Quote_terms1__r.size()>0 ){
                    termList.add(term.Quote_terms1__r);
                for(Quote_term__c q:term.Quote_terms1__r){
                   revertMap.put(q.id,term);                    
                }
            }
            else if(term.Active__c == true){
            termList.add(term);
            }
        }
        }
        PrevData = new List<Quote_term__c>(termList);
        return termList;
    }
    public pagereference revert(){
                  revertid = ApexPages.currentPage().getParameters().get('revertId');
          system.debug(revertid);
          update new Quote_term__c(id=revertid,Active__c=false);
        for(Quote_term__c q:termList){
            if(q.id==revertid){
                termList[termList.indexOf(q)] = revertMap.get(revertid);
            }
        }
          return null;
    }
    public pagereference save(){
     String standrdId = ApexPages.currentPage().getParameters().get('savedDataId');
     String body = ApexPages.currentPage().getParameters().get('changedTerm');
     String type = ApexPages.currentPage().getParameters().get('recordType');
        update termList;
        for(Quote_term__c quoTerm:termList){
           // update quoTerm;
            system.debug(quoTerm + 'out');
            if(!PrevData.contains(quoTerm)){
               system.debug(quoTerm);
            }
        }
        
        if(type=='Custom'){
            Quote_term__c Custom = new Quote_term__c(id=standrdId,body__c=body);
            update Custom;
           //system.debug(termList);
          // update termList;
        }
        system.debug(type);
        system.debug(standrdId);
        system.debug(body);
     return null;
    }
    
    public pagereference cancel(){
       
       return null;
    }
    public List<SelectOption> getTemplateOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        countryOptions.add(new SelectOption('','-None-'));
        for(Quote_Template__c QtTem : [Select id,name from Quote_Template__c]){
            countryOptions.add(new SelectOption(QtTem.name,QtTem.name));
        }
        return countryOptions;
    }
}



Test Class

@isTest
public class QuoteTermEditorControllertest {
@isTest
    public static void test(){

    Account act =new Account();
         act.Name = 'test';
         act.BillingCity='xyz';
         act.BillingCountry = 'xyz';
         act.BillingPostalCode = '2346';
         act.BillingState = 'xyz';
         act.BillingStreet = 'xyz';
         act.ShippingCity = 'xyz';
         act.ShippingCountry = 'xyz';
         act.ShippingPostalCode = '2346';
         act.ShippingState =  'xyz';
         act.ShippingStreet = 'xyz';
         insert act;
         
          Opportunity opp = new opportunity();
         opp.Name='test';
         opp.CloseDate=date.today().addMonths(2);
         opp.StageName='IsWon';
         opp.AccountId=act.Id;
        
        insert opp;
         
          Quote q = new Quote();
         q.name = 'Quote-' + opp.name;
         q.opportunityId = opp.id;
         q.Account__c = opp.AccountId;
         insert q;
        
        Quote_term__c quoterm = new Quote_term__c();
        quoterm.Quote_del__c = q.Id;
        quoterm.Name = 'test';
        quoterm.Print_Order__c = 23;
        insert quoterm;
        
        
        
        PageReference pageRef = Page.QuoteTermEditor;
        pageRef.getparameters().put('recordId', quoterm.id);  
        Test.setCurrentPage(pageRef);
        Apexpages.StandardController sc = new Apexpages.StandardController(quoterm);
        //ApexPages.currentPage().getParameters().put('id', quoterm.id);
        QuoteTermEditorController ext = new  QuoteTermEditorController();         
        ext.revert(); 
        ext.cancel();
        ext.save();

    }
}
public class IncludeDocumentController {
    //public blob attach{get;set;}
    public integer displayOrder{get;set;}
    public Additional_Document__c addattach{get;set;}
    public string recordId{get;set;}
    public string quoteNum{get;set;}
    public Quote quotes{get;set;}
    public list<Quote> listquote{get;set;}
    public Attachment myfile;
    ApexPages.StandardController sc;
   
    //includedocment controller
    public IncludeDocumentController(ApexPages.StandardController sc){
        this.sc = sc;
        listquote=new list<Quote>();
        recordId=ApexPages.CurrentPage().getparameters().get('id');
        for(Quote q:[select id,QuoteNumber from Quote where id=:recordId]){
            quoteNum=q.QuoteNumber;
        }
    }
    //get attched file
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
    
    // method to save file and redirect to quote page
    public pageReference save(){
        Attachment a = new Attachment(parentId = recordId, name=myfile.name, body = myfile.body);
        /*addattach=new Additional_Document__c();
        addattach.Name=myfile.name;
        addattach.External_Id__c=a.id;
        if(displayOrder!=null){
        addattach.Display_Order__c=displayOrder;
        }
        addattach.Quote__c=recordId;*/
        try {
            insert a;
            addattach=new Additional_Document__c();
            addattach.Name=myfile.name;
            addattach.External_Id__c=a.id;
            if(displayOrder!=null){
            addattach.Display_Order__c=displayOrder;
            }
            addattach.Quote__c=recordId;
            insert addattach;
        }
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
        }
        pageReference pr = new PageReference('/' + recordId );
        pr.setRedirect(true);
        if(myfile!=null){
        return pr;  
        }else{
               ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Attach File'));
        }
        return null;
    }
    
   //cancel method to redirect to quote page
    public pageReference cancel(){
        pageReference pr = new PageReference('/' + recordId );
        pr.setRedirect(true);
        return pr;
    }
   /* //importline page import button method
     public pageReference importLine(){
        pageReference pr = new PageReference('/' + recordId );
        pr.setRedirect(true);
        return pr;

     }*/
}
how to Create a gmail account automatic for new employees after completion of the probationary period.