• aamir arshad
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
public with sharing class ProductController {
    
    @AuraEnabled(cacheable=true)
    public static List<Product2Wrapper> getAllProduct2(){
        Map<String, Object> r = new Map<String, Object> ();  
        List<Product2Wrapper> proWrapperList = new List<Product2Wrapper>();
        String qry = 'SELECT Id, Name, Product2Id, Product2.Name ,Product2.Description, Product2.nodhom__Name_with_Code_Query__c, Product2.ProductCode, UnitPrice FROM PricebookEntry where IsActive = TRUE'; 
            qry += ' order by Product2.ProductCode ';
            for(PricebookEntry pro : DataBase.query(qry)){
                Product2Wrapper proWrapper = new Product2Wrapper();
                proWrapper.productId = pro.Product2Id;
                proWrapper.Name = pro.Product2.Name;
                proWrapper.NameWithCodeQuery = pro.Product2.nodhom__Name_with_Code_Query__c;
                proWrapper.ProductCode = pro.Product2.ProductCode;
                proWrapper.Description = pro.Product2.Description;
                proWrapper.unit = pro.UnitPrice;
                proWrapperList.add(proWrapper);
            }
        
        
        return proWrapperList;
    }

    @AuraEnabled(cacheable=true)
    public static List<Product2Wrapper> getAllProduct(Integer pageSize,Integer pageNumber){
        Map<String, Object> r = new Map<String, Object> ();  
        Integer offset = (pageNumber - 1) * pageSize;  

        Integer totalRecords = [SELECT COUNT() FROM Product2];
        Integer recordEnd = pageSize * pageNumber;

        List<Product2Wrapper> proWrapperList = new List<Product2Wrapper>();
        String qry = 'SELECT Id, Name, ProductCode, Net_Price__c, Standard_Margin__c, nodhom__Sales_Price__c, Description, nodhom__Name_with_Code_Query__c,Category_1__c, Category_2__c FROM Product2 where IsActive = TRUE  LIMIT :pageSize OFFSET :offset';
            for(Product2 pro : DataBase.query(qry)){
                Product2Wrapper proWrapper = new Product2Wrapper();
                proWrapper.productId = pro.Id;
                proWrapper.Name = pro.Name;
                proWrapper.NameWithCodeQuery = pro.nodhom__Name_with_Code_Query__c;
                proWrapper.ProductCode = pro.ProductCode;
                proWrapper.Description = pro.Description;
                Decimal netPrice;
                if(pro.Net_Price__c != null){
                proWrapper.netPrice = pro.Net_Price__c;
                 netPrice = pro.Net_Price__c;
                }else{
                  proWrapper.netPrice = 0;
                    netPrice = 0;
                }
                Decimal margin;
                if(pro.Standard_Margin__c != null){
                proWrapper.margin = pro.Standard_Margin__c;
                 margin = pro.Standard_Margin__c;
                }else{
                  proWrapper.margin = 0;
                    margin = 0;
                }
                proWrapper.unitPrice = netPrice+(netPrice*margin/100);
                proWrapper.totalAmount = 0;
                proWrapper.isChecked = false;
                proWrapper.productCategory1 = String.isBlank(pro.Category_1__c)?'':pro.Category_1__c;
                proWrapper.productCategory2 = String.isBlank(pro.Category_2__c)?'':pro.Category_2__c;
                proWrapper.pageNumber = pageNumber;
                proWrapper.pageSize = pageSize;        
                proWrapper.recordStart = offset + 1;
                proWrapper.recordEnd = totalRecords >= recordEnd ? recordEnd : totalRecords;
                proWrapper.totalRecords = totalRecords;

                proWrapperList.add(proWrapper);
            }
        
        
        return proWrapperList;
    }

    @AuraEnabled
    public static List<Map<String, String>> getPickListValues(String objApiName, String fieldName) {
        List < Map < String, String >> options = new List < Map < String, String >> ();
        Map < String, Schema.SObjectType > objGlobalMap = Schema.getGlobalDescribe();
        Schema.SObjectType objType = Schema.getGlobalDescribe().get(objApiName);
        if (objType == null) {
            return options;
        }
        Schema.DescribeSObjectResult sobjectDescribe = objType.getDescribe();
        Map < String, Schema.SObjectField > fieldMap = sobjectDescribe.fields.getMap();
        if (fieldMap.get(fieldName) == null) {
            return options;
        }
        List < Schema.PicklistEntry > pickListValues = fieldMap.get(fieldName).getDescribe().getPickListValues();
        for (Schema.PicklistEntry f: pickListValues) {
            Map < String, String > values = new Map < String, String > {
                'label' => f.getLabel(),
                'value' => f.getValue()
            };
            options.add(values);
        }
        return options;
    }

    @AuraEnabled
    public static void saveAllProducts(String recordId,String selectedProducts){
        List<Product2Wrapper> selectedProductsList = (List<Product2Wrapper>) JSON.deserialize(
           selectedProducts,
           List<Product2Wrapper>.class
        );

        List<Deal_Line_Item__c> dealLineList = new  List<Deal_Line_Item__c>();

        for(Product2Wrapper pro : selectedProductsList){
            Deal_Line_Item__c dlines = new Deal_Line_Item__c();
            dlines.Deal_No__c = recordId;
            dlines.Margin__c = pro.margin;
            dlines.Quantity__c = String.valueOf(pro.quantity);
            dlines.Net_Price__c = pro.netPrice;
            dlines.Item__c = pro.productId;

            dealLineList.add(dlines);
        }

        try{

         if(!dealLineList.isEmpty())
            insert dealLineList;

        }catch(Exception e){
            system.debug(e);
        }
    }
      
    public class Product2Wrapper {
        @AuraEnabled
        public Id productId{get;set;}
        @AuraEnabled
        public String Name{get;set;}   
        @AuraEnabled
        public String NameWithCodeQuery{get;set;}     
        @AuraEnabled
        public String ProductCode{get;set;}           
        @AuraEnabled
        public String Description{get;set;}         
        @AuraEnabled
        public Decimal unit{get;set;}
        @AuraEnabled
        public Decimal netPrice{get;set;}
        @AuraEnabled
        public Decimal margin{get;set;}
        @AuraEnabled
        public Decimal unitPrice{get;set;}
        @AuraEnabled
        public Decimal totalAmount{get;set;}
        @AuraEnabled
        public Boolean isChecked{get;set;}    
        @AuraEnabled
        public String productCategory1{get;set;}   
        @AuraEnabled
        public String productCategory2{get;set;}   
        @AuraEnabled
        public Decimal quantity{get;set;}   
        @AuraEnabled
        public Decimal recordStart{get;set;} 
        @AuraEnabled
        public Decimal pageNumber{get;set;} 
        @AuraEnabled
        public Decimal totalRecords{get;set;} 
        @AuraEnabled
        public Decimal recordEnd{get;set;} 
        @AuraEnabled
        public Decimal pageSize{get;set;}            
    } 
}

Hi

I need to add new picklist value in Standard Account  with help of apex

public class Mixed_DML_Example {
  
    public  void callMe(){
           Profile p = [SELECT Id FROM Profile WHERE Name='Test'];
        UserRole r = [SELECT Id FROM UserRole WHERE Name='Manager'];
        // Create new user with a non-null user role ID 
        User u = new User(alias = 'welll', email='salesforcebatch111@gmail.com', 
            emailencodingkey='UTF-8', lastname='wilson11', 
            languagelocalekey='en_US', 
            localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
            timezonesidkey='America/Los_Angeles', 
            username='wilsonDev@221Test.com');
        insert u;
            
            
            Account acc= new Account();
             acc.Name='Testing';
             acc.Phone='12345';
            acc.Rating='Hot';
            insert acc;
            
    }
}
a custom field on Contact "Salary"

a custom field on Account "Average Salary"

We need to calculate "Average salary" whenever a new contact insert/update/delete
public class Mixed_DML_Example {
  
    public  void callMe(){
           Profile p = [SELECT Id FROM Profile WHERE Name='Test'];
        UserRole r = [SELECT Id FROM UserRole WHERE Name='Manager'];
        // Create new user with a non-null user role ID 
        User u = new User(alias = 'welll', email='salesforcebatch111@gmail.com', 
            emailencodingkey='UTF-8', lastname='wilson11', 
            languagelocalekey='en_US', 
            localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
            timezonesidkey='America/Los_Angeles', 
            username='wilsonDev@221Test.com');
        insert u;
            
            
            Account acc= new Account();
             acc.Name='Testing';
             acc.Phone='12345';
            acc.Rating='Hot';
            insert acc;
            
    }
}

Hi,

 

When I am migrating data from Sandbox to developer org through Eclipse, Reports which are having filters are not being moved and the error is " Problem: filterlanguage: Invalid value specified: 1."

 

Once i remove the filter, I am able to move the reports successfully.

 

Anyone please help me in resolving this issue.

 

Thanks in advance.