• syed akram
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 41
    Replies

My requiremenrt is suppose i have 10 opportunity with same closed date with same opportunity owner then workflow will send 10 mail to same address i.e 10 mail, but i want one email need to send which contain all 10 opportunity list in table.that can be done through schedular class.i tried my self but i am not getting the exact result.

global class Opp_Scheduled Implements Schedulable
    {
     Map<Id , List<Opportunity>> oppMap {get; set;}
        global void execute(SchedulableContext sc)
        {
            setopplist();
        }


        public void setopplist()
        {
        
         Date d = Date.today();
        //Map to maintain opportunity id 
       oppMap = new Map<Id, List<Opportunity>>() ;
       
       //All opportunity closeDate 
       List<Opportunity> opplist = new List<Opportunity>() ;
       opplist = [select id, name, Owner.id, StageName, closeDate from Opportunity where CloseDate >= :d AND CloseDate <=:d-7];    
       List<Id> Idlist = new List<Id>() ;
       for(Opportunity opp : opplist )
       {
           Idlist.add(opp.owner.id) ;
       }
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
           List<String> toAddresses = new List<String>();  
            mail.setTemplateId('00Xe0000000RUOp');
           //Setting user email in to address
             
            toAddresses.add('Syed.Akram@cyient.com');
             mail.setToAddresses(toAddresses);
    
              //Email subject to be changed
              mail.setSubject('Opportunity Expired');
              
              //Body of email
              mail.setHtmlBody('Hi ');
                  
        }
    }

 
Hi i want to send the email to opportunity owner for the upcoming opportunities which is expiering next week.
here is my cntroller code
 public with sharing class TwilioCloudCommunicationClass {  
      
    // Public Properties  
    public String SelectedMobileNumber{get;set;}  
    public String OtherMobileNumber{get;set;}  
    public String textMessage{get;set;}
    // Default construtor  
    public TwilioCloudCommunicationClass()  
    {  
        SelectedMobileNumber  = '' ;  
        OtherMobileNumber = '' ;  
    }  
      
    Public List getPersonList()  
    {  
        Try{  
            List localList = new List();  
            localList.add(new SelectOption('' , '--Select--'));  
            for(contact cont : [select Name,MobilePhone from contact where TwilioRegisteredUser__c = true ])  
            {  
                localList.add(new SelectOption(cont.MobilePhone , cont.Name));            
            }        
            localList.add(new SelectOption('other' , 'Other'));  
            return localList ;  
        }  
        
        catch(Exception e)  
        {  
            ApexPages.addMessages(e);        
            return null;  
        }  
        
    }  
      
    public void SendSMS()  
    {  
        Try{        
            SelectedMobileNumber = (SelectedMobileNumber == '')? OtherMobileNumber:SelectedMobileNumber ;  
            if(SelectedMobileNumber != '')  
            {  
                List AdminInfo = TwilioConfig__c.getall().values();  
                String ACCOUNT_SID = '';  
                String AUTH_TOKEN  = '' ;              
                String SenderMobileNumber = '' ;  
                // Informaton getting from custom setting  
                if(AdminInfo.size()>0)  
                {            
                    ACCOUNT_SID             = AdminInfo[0].AccountSid__c;  
                    AUTH_TOKEN              = AdminInfo[0].AuthToken__c;                  
                    SenderMobileNumber      = AdminInfo[0].Admin_Mobile_Number__c;      
                }              
                TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);  
                 
                Map properties = new Map {  
                            'To'   => SelectedMobileNumber ,  
                            'From' => SenderMobileNumber,  
                            'Body' => textMessage  
                    };  
                TwilioSMS message = client.getAccount().getSmsMessages().create(properties);  
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Message has been sent'));  
            }  
            else  
            {  
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Pelase provide valid Mobile Number '));  
            }  
        }catch(Exception e )  
        {  
            ApexPages.addMessages(e);        
            return ;  
        }    
    }       
    } 
Can anyone help me to solve this?
Controller class Bold Text lines are not covering

public class AddPaymentController {
 public Payment__C paymentObj {get;set;}
 Public String invId {get;set;}
    public AddPaymentController(ApexPages.StandardController controller) {
       if(paymentObj == null) {
           paymentObj = new Payment__C();
           String invId = ApexPages.CurrentPage().getParameters().get('invid');
             if(invId !=null) {
     Invoice__c invObj = [Select Prospect_Client__r.ShippingPostalCode,Prospect_Client__r.ShippingState,Prospect_Client__r.Cell_Phone__c,Prospect_Client__r.Email__c,Prospect_Client__r.ShippingStreet,Prospect_Client__r.Name,Prospect_Client_City__c,Name,Id From Invoice__c i where id =:invId];
                           
                      if(invObj !=null) {
                          paymentObj.invoice_numbers__c = invObj.Name;
                          paymentObj.Invoice_Number__c = invObj.id;                        
                          paymentObj.City__c=invObj.Prospect_Client_City__c;         
                          paymentObj.State__c=invObj.Prospect_Client__r.ShippingState;
                          paymentObj.Zip__c=invObj.Prospect_Client__r.ShippingPostalCode;
                          paymentObj.Name__c=invObj.Prospect_Client__r.Name;
                          paymentObj.Street__c=invObj.Prospect_Client__r.ShippingStreet;
                          paymentObj.Phone__c=invObj.Prospect_Client__r.Cell_Phone__c;
                          paymentObj.Email_Address__c=invObj.Prospect_Client__r.Email__c;    
                         
                      }                           
             }
       }
    }       
   public Pagereference save(){
   
       if(paymentObj.Amount__c==null)
       {
       ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'please enter Amount and insert.');
            ApexPages.addMessage(myMsg);
       }                         
         upsert paymentObj;
        //  ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Payment Created Successfully.Thank you!'));   
          Pagereference refpyob = new Pagereference('/apex/Invoice?id='+paymentObj.Invoice_Number__c);                   
          refpyob.setRedirect(true);
          return refpyob; 
                                     
}       
}

test class i am getting 84 percent


@isTest

public with sharing class TestAddPaymentController{
  public static testMethod void unitTestInvoice7()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
      String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
      
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
       //ApexPages.currentPage().getParameters().put('invid',objInv.id);
       
       
      // ApexPages.Message[] pageMessages = ApexPages.getMessages();
     //      System.assertNotEquals(0, pageMessages.size());
           
          
     //  PageReference pageRef =Page.Invoice;
     // Test.setCurrentPageReference(pageRef);
     
   //   ApexPages.CurrentPage().getParameters().put('retURL','/apex/Invoice?id='+objInv.Id);
       
    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
  public static testMethod void unitTestInvoice8()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
     // String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
             

       
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
      
      PageReference testPage = new pagereference('/apex/Invoice?id='+objInv.Id);
      //change the following to opp.id instead of 'opp.id'
      //   testPage.getParameters().put('invid',objInv.id);

               Test.setCurrentPage(testPage);                    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
 
}
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
here is my controller class 
public without sharing class UpdateList {
    list<order> selectorder;
    String quoteId {set; get;}
    String selectedOrderId {set; get;}
    public List<Order> selectedOrders {set; get;}
    public Boolean orderUpdated {set; get;}    
    public UpdateList(){
        quoteId = ApexPages.currentPage().getParameters().get('quoteID');
        orderUpdated = false;
    } 
    public PageReference selectOrder(){
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
        return null;
    }    
    public list<Order> getorderslist()
    {
        List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
        return allords;
    }    
    //call this method to update order, and copy all quote line items from quote
    public PageReference updateOrder(){     
        //get selected orderId from the list   
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        //get quote line items using the quoteId
        List<OrderItem> orderLines = new List<OrderItem>(); 
        for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, 
                                   Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
            OrderItem oLine         = new OrderItem();
            oLine.OrderId           = selectedOrderId;
            oLine.PricebookEntryId  = qLine.PricebookEntryId;
            oLine.Quantity          = qLine.Quantity;
            oLine.UnitPrice         = qLine.UnitPrice;
            oLine.Description       = qLine.Description;
            oLine.ServiceDate       = qLine.ServiceDate;
            orderLines.add(oLine);
        } 
        insert orderLines;       
        orderUpdated = true;
         ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
        return null;       
    }    
}


here my test class
@istest (seeAllData=true)
private without sharing class TestUpdateList{
    
    Private static Account a;
    Private static Contact c;
    Private static Opportunity opp;
    Private static Quote q;
    Private static QuoteLineItem Qli;
    private static Order o;
    Static {    
        // Creating the data for Account,Contact,Opportunity,Quote and Order.
        
        a=new Account(Name='test1',Phone='9458383336');   // creating account with only mandatory Fields
        insert a;
        c = new Contact(LastName='Test',AccountId=a.Id);  // creating contact with only mandatory Fields
        insert c;
        
        // creating opportunity with only mandatory Fields
        opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
        insert opp;
        
        Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
        
        Product2 p = new product2(name='test',family='test',productcode='12345');
        insert p;
        System.debug('### p:'+p);
        
        PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
                                                unitprice=1.0, isActive=true,UseStandardPrice=false);
        insert pbe;
        
        // Creating Quote with only mandatory Fields
        q=new Quote(Name='testquote',opportunityId=opp.Id, pricebook2id=stdPb.id);
        insert q;
        // Creating Quote Line Items PricebookEntryId, Product2Id
        qli=new QuoteLineItem(QuoteId=q.Id,pricebookentryid=pbe.id, Quantity=12,UnitPrice=1500,Discount=0,Description='nothing',ServiceDate=system.today());
        insert qli;
        // Creating Order with mandatory Fields 
        o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
        insert o;                    
    }  
    // retreiving the order record and  working fine 25% code coverage with this method.
    Static TestMethod void Testgetorderslist(){
        Test.StartTest();

        PageReference pageRef=page.PrevOrder;
        pageRef.getParameters().put('quoteID',q.Id);
        Test.SetCurrentPageReference(pageRef);

        UpdateList ul=new UpdateList();
        List<order> orderList = ul.getorderslist();

        pageRef.getParameters().put('selectOrder',o.Id);
        ul.SelectOrder();
        ul.updateOrder();

        system.debug('test result ='+ orderList);
        system.assertEquals(orderList.size(),1);

        Test.StopTest();
    }
   
    Static TestMethod void TestselectOrder(){
        Test.StartTest();
        PageReference pageRef=page.PrevOrder;
        Test.SetCurrentPageReference(pageRef);
        ApexPages.currentPage().getParameters().put('ordersRadio',o.Id);   
        ApexPages.StandardController sc = new ApexPages.standardController(o);              
        UpdateList controller=new UpdateList();   
        controller.SelectOrder();  
        controller.UpdateOrder();
        Test.StopTest();    
    }    
}

i am getting the above error when i run my test class.
how to solve this?
 
here is the Controller code
public without sharing class UpdateList {
    list<order> selectorder;
    String quoteId {set; get;}
    String selectedOrderId {set; get;}
    public List<Order> selectedOrders {set; get;}
    public Boolean orderUpdated {set; get;}  

    public UpdateList(){
        quoteId = ApexPages.currentPage().getParameters().get('quoteID');
        orderUpdated = false;
    }    
    public PageReference selectOrder(){
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
        return null;
    }
    
    public list<Order> getorderslist()
    {
        List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
        return allords;
    }
    
    //call this method to update order, and copy all quote line items from quote
    public PageReference updateOrder(){
        
        //get selected orderId from the list   
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');

        //get quote line items using the quoteId
        List<OrderItem> orderLines = new List<OrderItem>(); 
        for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, 
                                   Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
            OrderItem oLine         = new OrderItem();
            oLine.OrderId           = selectedOrderId;
            oLine.PricebookEntryId  = qLine.PricebookEntryId;
            oLine.Quantity          = qLine.Quantity;
            oLine.UnitPrice         = qLine.UnitPrice;
            oLine.Description       = qLine.Description;
            oLine.ServiceDate       = qLine.ServiceDate;
            orderLines.add(oLine);
        }               
        insert orderLines;
         orderUpdated = true;
         ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
        return null;                     
    }    
}

here is the test class i have written till now i have written for one method and getting 25% code coverage
@istest
private class TestUpdateList{
    
    Private static Account a;
    Private static Contact c;
    Private static Opportunity opp;
    Private static Quote q;
    private static Order o;
   Static {    
    // Creating the data for Account,Contact,Opportunity,Quote and Order.
    
           a=new Account(Name='test1',Phone='9458383336');   // creating account with only mandatory Fields
            insert a;
           c = new Contact(LastName='Test',AccountId=a.Id);  // creating contact with only mandatory Fields
            insert c;
            
    // creating opportunity with only mandatory Fields
           opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
            insert opp;
            
    // Creating Quote with only mandatory Fields
           q=new Quote(Name='testquote',opportunityId=opp.Id);
            insert q;
           o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
            insert o;                    
   }  
   // retreiving the order record and  working fine 25% code coverage with this method.
      Static TestMethod void Testgetorderslist(){
      Test.StartTest();
      PageReference pageRef=page.PrevOrder;
      Test.SetCurrentPageReference(pageRef);
      system.currentPageReference().getParameters().put('Id', o.id);
      string ol = system.currentPageReference().getParameters().get('Id');
      system.debug('o.Id = '+ ol);
      UpdateList ul=new UpdateList();
      List<order> orderList = ul.getorderslist();
      system.debug('test result ='+ orderList);
      system.assertEquals(orderList.size(),1);
      Test.StopTest();
      }
    
    //
    Static TestMethod void TestselectOrder(){
    PageReference pageRef=page.PrevOrder;
    Test.SetCurrentPageReference(pageRef);
    Test.StartTest();
    
   // ApexPages.StandardController sc = new ApexPages.standardController(o);
   // UpdateList controller=new UpdateList(sc);
   // controller.SelectOrder();
    
    
    }
    
    Static TestMethod void TestUpdateOrder(){
    }
}

Please help me to write the test for TestSelectOrder() ?
here my Controller class

public class SalesOrder {
  public Order record{get;set;}
    public SalesOrder (ApexPages.standardcontroller std)
     { 
       record = new Order();           
     } 
  public pagereference dosave(){
      record.QuoteId = ApexPages.currentPage().getParameters().get('quoteID');
       insert record;
       ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
       pagereference page=new pagereference('/apex/SalesOrder');         
       return page;         
    }     
  public pageReference Cancel(){        
         pagereference page = new pageReference('/apex/QuoteVfPage');
         page.setRedirect(true);
         return page;
     }   
}
 here is test class

@istest
Private class TestSalesOrder{
    Static TestMethod void Dosave(){
        Test.startTest();
        
            PageReference pageRef = Page.SalesOrder;
            Test.setCurrentPageReference(pageRef);
            Account a=new Account(Name='test1',Phone='9458383336');   // creating account with only mandatory Fields
            insert a;
            Contact c = new Contact(LastName='Test',AccountId=a.Id);  // creating contact with only mandatory Fields
            insert c;
           // creating opportunity with only mandatory Fields
            Opportunity opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
            insert opp;
            // Creating Quote with only mandatory Fields
            Quote q=new Quote(Name='testquote',opportunityId=opp.Id);
            insert q;
            ApexPages.currentPage().getParameters().put('quoteID',q.Id );   
            Order ord = new Order(AccountId='a.Id',Name='test',status='draft',EffectiveDate=system.today());               
            Insert ord;
            ApexPages.standardcontroller std;
            SalesOrder sOrder = new SalesOrder(std);
            sOrder.dosave();
            sOrder.Cancel();
            
        Test.stopTest();
    }
    
    Static TestMethod void Cancel(){
        Test.StartTest();
        PageReference pageRef = Page.QuoteVfPage;
      Test.setCurrentPageReference(pageRef);
     }
}

when i am running my test class i am getting error 
public class SalesOrder {
  public Order record{get;set;}
    public SalesOrder (ApexPages.standardcontroller std)
     { 
       record = new Order();           
     } 
  public pagereference dosave(){
      record.QuoteId = ApexPages.currentPage().getParameters().get('quoteID');
       insert record;
       ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
       pagereference page=new pagereference('/apex/SalesOrder');     
       return page;        
    }     
  public pageReference Cancel(){        
         pagereference page = new pageReference('/apex/QuoteVfPage');
         page.setRedirect(true);
         return page;
     }   
}



here is the test class i have written correct me. i am new to salesforce

@istest
Private class TestSalesOrder{
 Static TestMethod void Dosave(){
  Test.startTest(); 
 PageReference pageRef = Page.SalesOrder;
Test.setCurrentPageReference(pageRef);
  String quoteId;
    if(!test.isrunningtest()) {
      quoteId = ApexPages.currentPage().getParameters().get('quoteID');
      Account a=new Account(Name='test1',Phone='9458383336');
     insert a;
     Order ord=new Order(AccountId=a.id,Name='test',status='draft',EffectiveDate=system.today());
     insert ord;
     }
     else
      {
      }
Test.stopTest();
}
Static TestMethod void Cancel(){
Test.StartTest();
PageReference pageRef = Page.QuoteVfPage;
Test.setCurrentPageReference(pageRef);
}
}
public without sharing class UpdateList {
    list<order> selectorder;
    String quoteId {set; get;}
    String selectedOrderId {set; get;}
    public List<Order> selectedOrders {set; get;}
    public Boolean orderUpdated {set; get;}
    
    public UpdateList(){
        quoteId = ApexPages.currentPage().getParameters().get('quoteID');
        orderUpdated = false;
    }
    
    public PageReference selectOrder(){
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
        return null;
    }
    
    public list<Order> getorderslist()
    {
        List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
        return allords;
    }
    
    //call this method to update order, and copy all quote line items from quote
    public PageReference updateOrder(){
        
        //get selected orderId from the list   
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');

        //get quote line items using the quoteId
        List<OrderItem> orderLines = new List<OrderItem>(); 
        for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, 
                                   Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
            OrderItem oLine         = new OrderItem();
            oLine.OrderId           = selectedOrderId;
            oLine.PricebookEntryId  = qLine.PricebookEntryId;
            oLine.Quantity          = qLine.Quantity;
            oLine.UnitPrice         = qLine.UnitPrice;
            oLine.Description       = qLine.Description;
            oLine.ServiceDate       = qLine.ServiceDate;
            orderLines.add(oLine);
        }      
        insert orderLines;    
        orderUpdated = true;
         ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
        return null;        
    }    
}
Hi i want to send the email to opportunity owner for the upcoming opportunities which is expiering next week.
here is my cntroller code
 public with sharing class TwilioCloudCommunicationClass {  
      
    // Public Properties  
    public String SelectedMobileNumber{get;set;}  
    public String OtherMobileNumber{get;set;}  
    public String textMessage{get;set;}
    // Default construtor  
    public TwilioCloudCommunicationClass()  
    {  
        SelectedMobileNumber  = '' ;  
        OtherMobileNumber = '' ;  
    }  
      
    Public List getPersonList()  
    {  
        Try{  
            List localList = new List();  
            localList.add(new SelectOption('' , '--Select--'));  
            for(contact cont : [select Name,MobilePhone from contact where TwilioRegisteredUser__c = true ])  
            {  
                localList.add(new SelectOption(cont.MobilePhone , cont.Name));            
            }        
            localList.add(new SelectOption('other' , 'Other'));  
            return localList ;  
        }  
        
        catch(Exception e)  
        {  
            ApexPages.addMessages(e);        
            return null;  
        }  
        
    }  
      
    public void SendSMS()  
    {  
        Try{        
            SelectedMobileNumber = (SelectedMobileNumber == '')? OtherMobileNumber:SelectedMobileNumber ;  
            if(SelectedMobileNumber != '')  
            {  
                List AdminInfo = TwilioConfig__c.getall().values();  
                String ACCOUNT_SID = '';  
                String AUTH_TOKEN  = '' ;              
                String SenderMobileNumber = '' ;  
                // Informaton getting from custom setting  
                if(AdminInfo.size()>0)  
                {            
                    ACCOUNT_SID             = AdminInfo[0].AccountSid__c;  
                    AUTH_TOKEN              = AdminInfo[0].AuthToken__c;                  
                    SenderMobileNumber      = AdminInfo[0].Admin_Mobile_Number__c;      
                }              
                TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);  
                 
                Map properties = new Map {  
                            'To'   => SelectedMobileNumber ,  
                            'From' => SenderMobileNumber,  
                            'Body' => textMessage  
                    };  
                TwilioSMS message = client.getAccount().getSmsMessages().create(properties);  
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Message has been sent'));  
            }  
            else  
            {  
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Pelase provide valid Mobile Number '));  
            }  
        }catch(Exception e )  
        {  
            ApexPages.addMessages(e);        
            return ;  
        }    
    }       
    } 
Can anyone help me to solve this?
Controller class Bold Text lines are not covering

public class AddPaymentController {
 public Payment__C paymentObj {get;set;}
 Public String invId {get;set;}
    public AddPaymentController(ApexPages.StandardController controller) {
       if(paymentObj == null) {
           paymentObj = new Payment__C();
           String invId = ApexPages.CurrentPage().getParameters().get('invid');
             if(invId !=null) {
     Invoice__c invObj = [Select Prospect_Client__r.ShippingPostalCode,Prospect_Client__r.ShippingState,Prospect_Client__r.Cell_Phone__c,Prospect_Client__r.Email__c,Prospect_Client__r.ShippingStreet,Prospect_Client__r.Name,Prospect_Client_City__c,Name,Id From Invoice__c i where id =:invId];
                           
                      if(invObj !=null) {
                          paymentObj.invoice_numbers__c = invObj.Name;
                          paymentObj.Invoice_Number__c = invObj.id;                        
                          paymentObj.City__c=invObj.Prospect_Client_City__c;         
                          paymentObj.State__c=invObj.Prospect_Client__r.ShippingState;
                          paymentObj.Zip__c=invObj.Prospect_Client__r.ShippingPostalCode;
                          paymentObj.Name__c=invObj.Prospect_Client__r.Name;
                          paymentObj.Street__c=invObj.Prospect_Client__r.ShippingStreet;
                          paymentObj.Phone__c=invObj.Prospect_Client__r.Cell_Phone__c;
                          paymentObj.Email_Address__c=invObj.Prospect_Client__r.Email__c;    
                         
                      }                           
             }
       }
    }       
   public Pagereference save(){
   
       if(paymentObj.Amount__c==null)
       {
       ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'please enter Amount and insert.');
            ApexPages.addMessage(myMsg);
       }                         
         upsert paymentObj;
        //  ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Payment Created Successfully.Thank you!'));   
          Pagereference refpyob = new Pagereference('/apex/Invoice?id='+paymentObj.Invoice_Number__c);                   
          refpyob.setRedirect(true);
          return refpyob; 
                                     
}       
}

test class i am getting 84 percent


@isTest

public with sharing class TestAddPaymentController{
  public static testMethod void unitTestInvoice7()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
      String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
      
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
       //ApexPages.currentPage().getParameters().put('invid',objInv.id);
       
       
      // ApexPages.Message[] pageMessages = ApexPages.getMessages();
     //      System.assertNotEquals(0, pageMessages.size());
           
          
     //  PageReference pageRef =Page.Invoice;
     // Test.setCurrentPageReference(pageRef);
     
   //   ApexPages.CurrentPage().getParameters().put('retURL','/apex/Invoice?id='+objInv.Id);
       
    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
  public static testMethod void unitTestInvoice8()
  {
 try{
 
// String strRetUrl = ApexPages.CurrentPage().getParameters().put('retURL','/apex/AddPaymentVFPage');
       User objUser =[select Id, Name ,Email from User Where UserName = 'naveen@cloudprousa.com.test'];
          
          Staff__c objStaff = new Staff__c(User__c = objUser.Id,Name='Naveen1',Last_Name__c='Alasapuri1');
          insert objStaff;
          
          Account objAcc = new Account(Name = 'Test Prospect4', OwnerId=objUser.Id, Company_Name__c='test',Sales_Consultant__c = objStaff.Id,
                         Cell_Phone__c='987', ShippingStreet='test', ShippingCity='test', ShippingState='NJ');
          insert objAcc;
            Lead_Source__c objLS = new Lead_Source__c ( Name = 'Test Lead',Sales_Consultant__c =objStaff.Id);
      insert objLS;
          
            //SalesWorksheet record insertion
            
            Salesworksheet__c objSW = new Salesworksheet__c(C_Adjustment__c = 10,Lead_Source__c=objLS.Id);
            insert objSW;
            
            //User objUser =[select Id from User Where UserName = 'naveen@cloudprousa.com.test'];
            
            //Staff__c objStaff = new Staff__c(User__c = objUser.Id);
            //insert objStaff;
            
            Invoice__c objInv = new Invoice__c(Sales_Worksheet__c = objSW.Id);
            insert objInv;
            

            
            objSW.Technician__c = objStaff.Id;
            update objSW;
        //Payment record insertion
      Payment__c objPayment= new Payment__c(Amount__c=1000);
      insert objPayment;
        
     // insert objInv;
     // String strInvId = ApexPages.CurrentPage().getParameters().put('invid',objInv.id);
      
         
             

       
      
      ApexPages.StandardController controller = new ApexPages.StandardController(objPayment);
      AddPaymentController objCGC = new AddPaymentController(controller);
      objCGC.save();
      
      PageReference testPage = new pagereference('/apex/Invoice?id='+objInv.Id);
      //change the following to opp.id instead of 'opp.id'
      //   testPage.getParameters().put('invid',objInv.id);

               Test.setCurrentPage(testPage);                    
    }catch(exception e)
    {
      system.debug('Exception..'+e);
    }
  }
 
 
}
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
here is my controller class 
public without sharing class UpdateList {
    list<order> selectorder;
    String quoteId {set; get;}
    String selectedOrderId {set; get;}
    public List<Order> selectedOrders {set; get;}
    public Boolean orderUpdated {set; get;}    
    public UpdateList(){
        quoteId = ApexPages.currentPage().getParameters().get('quoteID');
        orderUpdated = false;
    } 
    public PageReference selectOrder(){
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
        return null;
    }    
    public list<Order> getorderslist()
    {
        List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
        return allords;
    }    
    //call this method to update order, and copy all quote line items from quote
    public PageReference updateOrder(){     
        //get selected orderId from the list   
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        //get quote line items using the quoteId
        List<OrderItem> orderLines = new List<OrderItem>(); 
        for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, 
                                   Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
            OrderItem oLine         = new OrderItem();
            oLine.OrderId           = selectedOrderId;
            oLine.PricebookEntryId  = qLine.PricebookEntryId;
            oLine.Quantity          = qLine.Quantity;
            oLine.UnitPrice         = qLine.UnitPrice;
            oLine.Description       = qLine.Description;
            oLine.ServiceDate       = qLine.ServiceDate;
            orderLines.add(oLine);
        } 
        insert orderLines;       
        orderUpdated = true;
         ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
        return null;       
    }    
}


here my test class
@istest (seeAllData=true)
private without sharing class TestUpdateList{
    
    Private static Account a;
    Private static Contact c;
    Private static Opportunity opp;
    Private static Quote q;
    Private static QuoteLineItem Qli;
    private static Order o;
    Static {    
        // Creating the data for Account,Contact,Opportunity,Quote and Order.
        
        a=new Account(Name='test1',Phone='9458383336');   // creating account with only mandatory Fields
        insert a;
        c = new Contact(LastName='Test',AccountId=a.Id);  // creating contact with only mandatory Fields
        insert c;
        
        // creating opportunity with only mandatory Fields
        opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
        insert opp;
        
        Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
        
        Product2 p = new product2(name='test',family='test',productcode='12345');
        insert p;
        System.debug('### p:'+p);
        
        PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
                                                unitprice=1.0, isActive=true,UseStandardPrice=false);
        insert pbe;
        
        // Creating Quote with only mandatory Fields
        q=new Quote(Name='testquote',opportunityId=opp.Id, pricebook2id=stdPb.id);
        insert q;
        // Creating Quote Line Items PricebookEntryId, Product2Id
        qli=new QuoteLineItem(QuoteId=q.Id,pricebookentryid=pbe.id, Quantity=12,UnitPrice=1500,Discount=0,Description='nothing',ServiceDate=system.today());
        insert qli;
        // Creating Order with mandatory Fields 
        o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
        insert o;                    
    }  
    // retreiving the order record and  working fine 25% code coverage with this method.
    Static TestMethod void Testgetorderslist(){
        Test.StartTest();

        PageReference pageRef=page.PrevOrder;
        pageRef.getParameters().put('quoteID',q.Id);
        Test.SetCurrentPageReference(pageRef);

        UpdateList ul=new UpdateList();
        List<order> orderList = ul.getorderslist();

        pageRef.getParameters().put('selectOrder',o.Id);
        ul.SelectOrder();
        ul.updateOrder();

        system.debug('test result ='+ orderList);
        system.assertEquals(orderList.size(),1);

        Test.StopTest();
    }
   
    Static TestMethod void TestselectOrder(){
        Test.StartTest();
        PageReference pageRef=page.PrevOrder;
        Test.SetCurrentPageReference(pageRef);
        ApexPages.currentPage().getParameters().put('ordersRadio',o.Id);   
        ApexPages.StandardController sc = new ApexPages.standardController(o);              
        UpdateList controller=new UpdateList();   
        controller.SelectOrder();  
        controller.UpdateOrder();
        Test.StopTest();    
    }    
}

i am getting the above error when i run my test class.
how to solve this?
 
here is the Controller code
public without sharing class UpdateList {
    list<order> selectorder;
    String quoteId {set; get;}
    String selectedOrderId {set; get;}
    public List<Order> selectedOrders {set; get;}
    public Boolean orderUpdated {set; get;}  

    public UpdateList(){
        quoteId = ApexPages.currentPage().getParameters().get('quoteID');
        orderUpdated = false;
    }    
    public PageReference selectOrder(){
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
        selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
        return null;
    }
    
    public list<Order> getorderslist()
    {
        List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
        return allords;
    }
    
    //call this method to update order, and copy all quote line items from quote
    public PageReference updateOrder(){
        
        //get selected orderId from the list   
        selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');

        //get quote line items using the quoteId
        List<OrderItem> orderLines = new List<OrderItem>(); 
        for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate, 
                                   Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
            OrderItem oLine         = new OrderItem();
            oLine.OrderId           = selectedOrderId;
            oLine.PricebookEntryId  = qLine.PricebookEntryId;
            oLine.Quantity          = qLine.Quantity;
            oLine.UnitPrice         = qLine.UnitPrice;
            oLine.Description       = qLine.Description;
            oLine.ServiceDate       = qLine.ServiceDate;
            orderLines.add(oLine);
        }               
        insert orderLines;
         orderUpdated = true;
         ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
        return null;                     
    }    
}

here is the test class i have written till now i have written for one method and getting 25% code coverage
@istest
private class TestUpdateList{
    
    Private static Account a;
    Private static Contact c;
    Private static Opportunity opp;
    Private static Quote q;
    private static Order o;
   Static {    
    // Creating the data for Account,Contact,Opportunity,Quote and Order.
    
           a=new Account(Name='test1',Phone='9458383336');   // creating account with only mandatory Fields
            insert a;
           c = new Contact(LastName='Test',AccountId=a.Id);  // creating contact with only mandatory Fields
            insert c;
            
    // creating opportunity with only mandatory Fields
           opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
            insert opp;
            
    // Creating Quote with only mandatory Fields
           q=new Quote(Name='testquote',opportunityId=opp.Id);
            insert q;
           o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
            insert o;                    
   }  
   // retreiving the order record and  working fine 25% code coverage with this method.
      Static TestMethod void Testgetorderslist(){
      Test.StartTest();
      PageReference pageRef=page.PrevOrder;
      Test.SetCurrentPageReference(pageRef);
      system.currentPageReference().getParameters().put('Id', o.id);
      string ol = system.currentPageReference().getParameters().get('Id');
      system.debug('o.Id = '+ ol);
      UpdateList ul=new UpdateList();
      List<order> orderList = ul.getorderslist();
      system.debug('test result ='+ orderList);
      system.assertEquals(orderList.size(),1);
      Test.StopTest();
      }
    
    //
    Static TestMethod void TestselectOrder(){
    PageReference pageRef=page.PrevOrder;
    Test.SetCurrentPageReference(pageRef);
    Test.StartTest();
    
   // ApexPages.StandardController sc = new ApexPages.standardController(o);
   // UpdateList controller=new UpdateList(sc);
   // controller.SelectOrder();
    
    
    }
    
    Static TestMethod void TestUpdateOrder(){
    }
}

Please help me to write the test for TestSelectOrder() ?
Hi guys,
I was woundering if there are any good website/books for learning Apex, I have never done coding and I am struggling with the basic concepts of the language and what goes were. The Salesforce trailhead for Apex does not make alot of sence to me at all or the Apex dev guild.
If anybody can help me by pointing me in the right direction that would be most helpful.  
Regards