• Suraj_Bahale
  • NEWBIE
  • 150 Points
  • Member since 2019
  • Salesforce Developer
  • XenLabs

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 6
    Replies
I tried to get data from the controller only by using "ORDER BY DESC" but I used two queries so it's sorting but dividing report into two sections...

Since I used Map so it does not support Sort()...

How can I sort all data in the controller, by Descending to Ascending?

Source Code:
list<Account> ShipToAccList = [Select ID from Account WHERE ParentID =: accId];
	//Previous Year
		list<AggregateResult> PrevYear_AGG = [Select CC_Product__r.ccrz__SKU__c PRODUCTSKU, 
												SUM(Quantity_Shipped__c) QTYSHIPPED 
												FROM
												CC_Shipment_Line_Items__c 
												WHERE CC_Shipment__r.Account__c IN : ShipToAccList  
												AND CC_Shipment__r.Date_Shipped__c >= LAST_YEAR 
												AND CC_Shipment__r.Date_Shipped__c < THIS_YEAR GROUP BY CC_Product__r.ccrz__SKU__c 
												ORDER BY SUM(Quantity_Shipped__c) DESC];

	set<string> productset = new set<string>();
	for(AggregateResult aggrstlst : PrevYear_AGG){
		if(!(productset).contains((string)aggrstlst.get('PRODUCTSKU'))){
			productset.add((string)aggrstlst.get('PRODUCTSKU'));    
		}        
	}

	//Current Year
	list<AggregateResult> CurrYear_AGG = [Select CC_Product__r.ccrz__SKU__c PRODUCTSKU, SUM(Quantity_Shipped__c) QTYSHIPPED 
										  FROM  CC_Shipment_Line_Items__c 
										  WHERE
										  CC_Shipment__r.Account__c IN : ShipToAccList
										  AND CC_Shipment__r.Date_Shipped__c = THIS_YEAR
										  GROUP BY CC_Product__r.ccrz__SKU__c
										  ORDER BY SUM(Quantity_Shipped__c) DESC
										 ];

	//Get Aggregate values in a Map
	Map<string,object> AG_Map = new Map<string,object>();

	//Mapping :: Previous year
	for(AggregateResult aggrstlst : PrevYear_AGG){ 
		
		list<integer> prvlist = new list<integer>();
		// prev yr
		prvlist.add(integer.valueOf((Double)aggrstlst.get('QTYSHIPPED')));
		//curr yr
		prvlist.add(0);
		
		AG_Map.put((string)aggrstlst.get('PRODUCTSKU') , prvlist);
	}
	//system.debug(AG_Map);

	//Mapping :: Current year
	for(AggregateResult aggrstlst : CurrYear_AGG){
		if((AG_Map.keySet()).contains((string)aggrstlst.get('PRODUCTSKU'))){// if Product FOUND in AG_MAP    
			((list<object>)AG_Map.get((string)aggrstlst.get('PRODUCTSKU')))[1] = integer.valueOf((Double)aggrstlst.get('QTYSHIPPED')); 
			
		} 
		else{// if Product not in AG_MAP
			list<integer> prvlist = new list<integer>();
			// prev yr
			prvlist.add(integer.valueOf((Double)aggrstlst.get('QTYSHIPPED')));
			//curr yr
			prvlist.add(0);
			
			AG_Map.put((string)aggrstlst.get('PRODUCTSKU'), prvlist);
		}
	}
	  
	//GETTING PROD DESCRITION AND FAMILY
	Map<string,list<object>> ProdDetailsMap = new Map<string,list<object>>();
	for(ccrz__E_Product__c ProdInst : [SELECT ID, PCC_Family_Name__c,
									   ccrz__ShortDescRT__c,ccrz__SKU__c 
									   FROM ccrz__E_Product__c 
									   WHERE ccrz__SKU__c IN : AG_Map.keySet()]){
										   list<object> ProdD = new list<object>();
										   prodD.add(ProdInst.ccrz__ShortDescRT__c);
										   prodD.add(ProdInst.PCC_Family_Name__c);    
										   ProdDetailsMap.put(string.valueof(ProdInst.ccrz__SKU__c), ProdD);
									   }

	//Final Respoonse Map
	list<object> YOYPrimary = new list<object>();

	Map<integer, list<object>> beforesrt = new Map<integer, list<object>>();

	for(string objlst : AG_Map.keySet()){
		list<object> YOYinstance = new list<object>();
		
		AG_Map.get(objlst);
		
		//Allign prod SKU, desc and familiy
		string ProductSKU = string.valueOf(objlst);
		YOYinstance.add(ProductSKU);
		String PartDescription = string.valueOf(((list<object>) ProdDetailsMap.get(objlst))[0]);
		YOYinstance.add(PartDescription);
		string ProductFamilily;
		if(string.isBlank((string.valueOf(((list<object>) ProdDetailsMap.get(objlst))[1])))){
			ProductFamilily = 'NOT AVAILABLE';
		}else{
			ProductFamilily = string.valueOf(((list<object>) ProdDetailsMap.get(objlst))[1]);    
		}                
		YOYinstance.add(ProductFamilily);
		
		//calculate difference
		integer CYQty = integer.valueOf(((list<object>)AG_Map.get(objlst))[1]);
		YOYinstance.add(CYQty);
		integer LYQty = integer.valueOf(((list<object>)AG_Map.get(objlst))[0]);
		YOYinstance.add(LYQty);
		
		integer QtyDiff = CYQty - LYQty;                
		YOYinstance.add(QtyDiff);

		//calculate %difference 
		double PercentDiff = (decimal.valueof(QtyDiff)/decimal.valueof(LYQty))*100;
		YOYinstance.add(PercentDiff);

		YOYPrimary.add(YOYinstance);
		//####### MAP OF UNSORTED ######
		beforesrt.put(LYQty, YOYinstance);
	}
				
	//########### RESPONSE SECTION ###############################
	Map<string, object> responseYOY = new Map<string, object>();            
	responseYOY.put('YOYrecords', YOYPrimary);

	returnMap.put('YOYPrimary', YOYPrimary);

	res.success	= true;
	res.data 	= returnMap;

 
Shopping cart is not getting refresh on page reload.

i have written one custom fucntionality on shopping cart on storefront where i have added the one clear cart button on shopping cart.

Vf component:
<button class="btn btn-default btn-sm" id="DeleteAll" name="" type="button" onclick="deleteall(event);">{{pageLabelMap 'CartInc_DeleteAll'}}</button>


function deleteall(e){
        var cart_id =  CCRZ.cartDetailModel.attributes.sfid;
        // var cart_id = CCRZ.pagevars.currentCartID;
        console.log(cart_id); 
        
        var Eff_account_ID = CCRZ.pagevars.queryParams.effectiveAccount;
        console.log(Eff_account_ID);
        
       if(cart_id != undefined){
        console.log("i am in if loop");
        var remoteCall = _.extend(CCRZ.RemoteInvocation, { className: 'FIL_FGP_ProductListCtrl' });
        remoteCall.invokeCtx(
            'clearCart',cart_id , Eff_account_ID,
            function(response,event){
                if(response.success){
                    console.log("clearCart remote action called successfully");
                    //do something with the response
                    console.log(response);
                    location.reload();
                    
                }else{
                    CCRZ.pubSub.trigger('pageMessage', { messages: [{ type: 'CUSTOM', severity: 'ERROR', message:'You have no items in the Cart', classToAppend: 'messagingSection-Error'}] });
                    console.log("clearCart remote action called, but something went wrong");
                }
            },
            {
                buffer:false, //this call will be executed by itself
                nmsp : false //defines that this is a call to a subscriber class
            }
        );
        }else{
        console.log("do nothing");
        }
        
    }

Controller :
@RemoteAction
    global static ccrz.cc_RemoteActionResult clearCart( final ccrz.cc_RemoteActionContext ctx, String cart_id , string Ef_Account_ID){
        ccrz.cc_RemoteActionResult res = ccrz.cc_CallContext.init(ctx);
  
        system.debug('ControllerBegin');                       
        system.debug(ctx);
        //system.debug(sfids);
        system.debug(cart_id);
        

        List<ccrz__E_CartItem__c> item=[Select Id, Name, ccrz__Cart__c, ccrz__CartItemId__c, ccrz__ItemLabel__c, ccrz__Product__c FROM ccrz__E_CartItem__c WHERE ccrz__Cart__c = :cart_id];
        if(item.size()> 0){
            system.debug(item.size());
            system.debug(item);
            delete item;
            res.success = true;
        }else{
            system.debug('Empty Cart');
           res.success = false; 
        } 
        return res;
	}

The remote is going sucessfully and the cart items are getting deleted from the object at backend side .but on page reload the cart is not getting refreshed .It shows the previous quantity.

Thanks & Regards,
Suraj Bahale
Hello Everyone, I want to display Date in Date formate but it's showing in Milliseconds. 

i have attached vf code, query, and output on VF page.

How to display Date insted of Milliseconds.

Visualforce code:
<td>
{{#if this.CC_Shipment__r.Date_Shipped__c}}
{{this.CC_Shipment__r.Date_Shipped__c}}
{{else}}
   -
{{/if}}
</td>
Query:
SELECT CC_Shipment__r.Date_Shipped__c FROM CC_Shipment_Line_Items__c
Query Result:
Query result on Developer console

Output on VF page:
Output on VF page.

I want to convert this Milliseconds(1569283200000) and show it in Date formate (2019-09-24).

Thank you🙂
Can we declare more than one remote action on a single controller in salesforce using javascript remote calling?
i want to get only Updated and newly created records from custom object... How to get only Updated and newly created records using SOQL query?
A company wants to create an employee rating program that allows employees to rate each other. An employees average rating must be displayed on the employee record. Employees must be able to create rating records, but are not allowed to create employee records.
Which two actions should a developer take to accomplish this task?
Choose 2 answers


A. Create a master- detail relationship between the rating and employee objects.
B. Create a trigger on the rating object that updates a field on the employee object.
C. Create a lookup relationship between the rating and employee object.
D. Create a rollup summary field on the employee and use AVG to calculate the average rating score.
A. A controller extension method that saves a list of account records.
B. Custom javascript that processes a list of account records.
C. A controller extension method that uses SOQL to query for a list of account records
D. A list of account records returned from a controller extension method
Q. A change set deployment from a sandbox to production fails due to a failure in a managed package unit test. The developer spoke with the managed package owner and they determined it is a false positive and can be ignored. What should the developer to do successfully deploy?

A. Edit the managed package’s unit test.
B. Select fast deploy to run only the tests that are in the change set.
C. Select “Run local tests” to run only the tests that are in the change set.
D. Select “Run local tests” to run all tests in the org that are not in the managed package.
A. Use SOQL to get all Cases.
B. Use DescribeSObjectResult of the Case object.
C. Use Case.getRecordTypes().
D. Use DescribeFieldResult of the Case.RecordType field.
A. Call "acct.getSObjectType()"
B. Call "Account.getSObjectType()"
C. Call "Account.SObjectType".
D. Call "acct.SObjectType''.
A. To guarantee at least 50% of code is covered by unit tests before it is deployed
B. To ensure every usecase of the application is covered by a test
C. To confirm every trigger is executed at leat once.
D. To confirm all classes and triggers compile successfully
A.String qryName = ‘%’ + String.escapeSingleQuotes(name) + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE \ ' % ' + qryName + ' % \ ' ';
List<contact> queryResult =Database.query(queryString);


B. String qryName = ‘%’ + name + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE :qryName' ;
List<contact> queryResult =Database.query(queryString);

C. String qryString = ‘SELECT ID FROM contact WHERE name LIKE \ ‘%’ + name + ‘%\ ’ ’;
List<contact> queryResult =Database.query(queryString);

D. String qryName = ‘%’ + String.enforceSecurityChecks(name) + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE :qryName;
A. Call “Opportunity.StageName.Label”.
B. Call “Opportunity. StageName.getDescribe().getLabel()”.
C. Call “opp.StageName.getDescribe().getLabel()”.
D. Call “opp.StageName.Label”.
A. When concatenating fields, line breaks can be added to improve readability.
B. Fields that are referenced by a formula field can not be deleted until the formula is modified or deleted.
C. Formula fields may reference formula fields on the same object to a level of one deep.
D. When using the operator to concatenate strings, the result is automatically truncated to fit the destination.
A. Use a custom controller.
B. Use a custom controller with extensions.
C. Use a standard controller with extensions.
D. Do not specify a controller.
E. Use a standard controller.
A. includes a subset of metadata
B. requires a sandbox template
C. Supports more frequent refreshes
D. D. Provides more data record storage
How to create a static resource using apex class?
A.String qryName = ‘%’ + String.escapeSingleQuotes(name) + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE \ ' % ' + qryName + ' % \ ' ';
List<contact> queryResult =Database.query(queryString);


B. String qryName = ‘%’ + name + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE :qryName' ;
List<contact> queryResult =Database.query(queryString);

C. String qryString = ‘SELECT ID FROM contact WHERE name LIKE \ ‘%’ + name + ‘%\ ’ ’;
List<contact> queryResult =Database.query(queryString);

D. String qryName = ‘%’ + String.enforceSecurityChecks(name) + ‘%’;
String qryString = ‘SELECT ID FROM contact WHERE name LIKE :qryName;
Hello Everyone, I want to display Date in Date formate but it's showing in Milliseconds. 

i have attached vf code, query, and output on VF page.

How to display Date insted of Milliseconds.

Visualforce code:
<td>
{{#if this.CC_Shipment__r.Date_Shipped__c}}
{{this.CC_Shipment__r.Date_Shipped__c}}
{{else}}
   -
{{/if}}
</td>
Query:
SELECT CC_Shipment__r.Date_Shipped__c FROM CC_Shipment_Line_Items__c
Query Result:
Query result on Developer console

Output on VF page:
Output on VF page.

I want to convert this Milliseconds(1569283200000) and show it in Date formate (2019-09-24).

Thank you🙂
Can we declare more than one remote action on a single controller in salesforce using javascript remote calling?
i want to get only Updated and newly created records from custom object... How to get only Updated and newly created records using SOQL query?
Q. A change set deployment from a sandbox to production fails due to a failure in a managed package unit test. The developer spoke with the managed package owner and they determined it is a false positive and can be ignored. What should the developer to do successfully deploy?

A. Edit the managed package’s unit test.
B. Select fast deploy to run only the tests that are in the change set.
C. Select “Run local tests” to run only the tests that are in the change set.
D. Select “Run local tests” to run all tests in the org that are not in the managed package.
A. Call "acct.getSObjectType()"
B. Call "Account.getSObjectType()"
C. Call "Account.SObjectType".
D. Call "acct.SObjectType''.
A. When concatenating fields, line breaks can be added to improve readability.
B. Fields that are referenced by a formula field can not be deleted until the formula is modified or deleted.
C. Formula fields may reference formula fields on the same object to a level of one deep.
D. When using the operator to concatenate strings, the result is automatically truncated to fit the destination.