• zeenat mangat
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
Following is my code where I use query with group by cluse for sum up the quantity that has the same name.

public List<Order_Item__c> orders;
    public String email;
    public List<Order_Item__c> getOrders() {
        email ='se.dx@gmail.com';
        orders = [SELECT Chargent_Order__r.Id, Product_Code__c, SUM(Quantity__c), Chargent_Order__r.ChargentOrders__Total__c,           Product__r.Name, Chargent_Order__r.ChargentOrders__Billing_Email__c  FROM Order_Item__c WHERE Chargent_Order__r.ChargentOrders__Billing_Email__c =:email GROUP BY Product__r.Name];
   return orders;
    }

But it shows the above error please help me
Here is my apex class controller.
Below this I have created its test class.
please help me to find the problem.

@RestResource(urlMapping='/v2/addUpsell/*')
global with sharing class REST_Upsell_Controller {
       
    @HttpPost
    global static String processUpsell(String orderId, Decimal price, Decimal shipping, Decimal tax){       
  
        ChargentOrders__ChargentOrder__c order = [SELECT Id, ChargentOrders__Subtotal__c, ChargentOrders__Tax__c, ChargentOrders__Shipping__c FROM ChargentOrders__ChargentOrder__c WHERE Id = :orderId];
        
        
        Decimal prc = order.ChargentOrders__Subtotal__c;
        Decimal tx = order.ChargentOrders__Tax__c;
        Decimal shp = order.ChargentOrders__Shipping__c;
        
        if(tx!= null){
            order.ChargentOrders__Tax__c= tx+tax;
        }else{
            order.ChargentOrders__Tax__c= tax;
        }
        
        if(shp!= null){
            order.ChargentOrders__Shipping__c= shp+shipping;
        }else{
            order.ChargentOrders__Shipping__c= shipping;
        }
        
        order.ChargentOrders__Subtotal__c= prc+price;
                        
        try {
        
            /* Update Order with Upsell Amount */
            update  order;           
            return 'added';   
        } catch (DmlException e) {
             
            return 'false';
        }
    }   
}



Test class :-

@isTest(SeeAllData=true)
public class REST_Upsell_Controller_Test {
    static testMethod void testCreateNewUpsell(){
        String orderId = 'a0555000000N5BnAAK';
        Decimal price = 30.00;
        Decimal shipping = 20.55;
        Decimal tax = 12.22;
        
        Decimal prc = 10.00;
        Decimal tx = 20.22;
        Decimal shp = 15.20;
        
        Decimal txs = tx+tax;
        Decimal shps = shp+shipping;
        Decimal prcs = prc+price;
        ChargentOrders__ChargentOrder__c oderobj = new ChargentOrders__ChargentOrder__c();
        oderobj.ChargentOrders__Tax__c = txs;
        oderobj.ChargentOrders__Shipping__c = shps;
        oderobj.ChargentOrders__Subtotal__c = prcs;
        insert oderobj;
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        req.requestURI = '/v2/addUpsell/*';  //Request URL
        req.httpMethod = 'POST';//HTTP Request Type
        RestContext.request = req;
        RestContext.response= res;
        
        String strResponse = REST_Upsell_Controller.processUpsell('a0555000000N5BnAAK',30.00,20.55,12.22);
        System.assertEquals('added',strResponse);
    }
}
Can we create the test class of the Lead controller that uses the REST api for Request url like this:

eg-

@RestResource(urlMapping='/v2/getCharged/*')
global with sharing class REST_ChargeNT_Controller {
       
    @HttpPost
    global static String processPayment(String orderId){
@RestResource(urlMapping='/v2/setLead/*')
global with sharing class REST_Lead_Controller {
    
    @HttpPost
    global static String createLead(String email, String phone, String fname, String lname){
        
        List<Lead> anct = [SELECT Id from Lead  WHERE Email = :email]; 
          
        /* If PersonAccount's record does not exist */               
        if(anct.size() == 0){ 
            
            Lead lead = new Lead();
            List<String> temp = email.split('@');
            lead.FirstName = fname;
            lead.LastName = lname;
            lead.Email = email;      
            lead.Company = 'mcnabb';    
            lead.Status = 'Open'; 
            insert lead;
            return 'Added';
            
            
        }else if(phone != 'NA'){
            
        /* If PersonAccount's record already exist */                
            Lead lead= [SELECT Id, Phone, FirstName, LastName, Email, Company from Lead  WHERE Email   = :email];
            lead.Phone = phone; 
            lead.FirstName = fname;
            lead.LastName = lname;
            update lead;
            return 'Updated';
        }else{
        
             return 'Exist';
        }
    }
}

Please help me to create the test class of it. I have working on it from last 1 weak, but it cannot be successful.
Its very urgent.
@RestResource(urlMapping='/v2/setLead/*')
global with sharing class REST_Lead_Controller {
    
    @HttpPost
    global static String createLead(String email, String phone, String fname, String lname){
        
        List<Lead> anct = [SELECT Id from Lead  WHERE Email = :email]; 
          
        /* If PersonAccount's record does not exist */               
        if(anct.size() == 0){ 
            
            Lead lead = new Lead();
            List<String> temp = email.split('@');
            lead.FirstName = fname;
            lead.LastName = lname;
            lead.Email = email;      
            lead.Company = 'mcnabb';    
            lead.Status = 'Open'; 
            insert lead;
            return 'Added';
            
            
        }else if(phone != 'NA'){
            
        /* If PersonAccount's record already exist */                
            Lead lead= [SELECT Id, Phone, FirstName, LastName, Email, Company from Lead  WHERE Email   = :email];
            lead.Phone = phone; 
            lead.FirstName = fname;
            lead.LastName = lname;
            update lead;
            return 'Updated';
        }else{
        
             return 'Exist';
        }
    }
}

Please help me to create the test class of it. I have working on it from last 1 weak, but it cannot be successful.
Its very urgent.