• Jasjeet Grewal
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
Hi All,

I am calling a static method of a class from another class. I can only invoke a static method not a constructor to assign values to properties of a class.

Now, I want to assign values to properties of a class. These properties will be accessed by VF using getter.

Here's a brief code:
 
public with sharing class PdfGenerator {

    public Order__c orderVF {get; set;}
    public List<Order_Line_Item__c>orderLineItemsVF {get; set;}

public static void generateOrderPDF(ID OrderID){
        Order__c order = [SOQL];
        Order_Line_Item__c orderLineItem = [SOQL];

       //how to pass this variable value to class properties orderVF and orderLineItemsVF?
       //I am basically calling this static method from another class. PdfGenerator.generateOrderPDF(Id);

}
any idea how can i pass value to class properties from within static method of a class?
Hi,

As logged in user to LWC, I need to display user's related Account details on LWC page.
User object has standard field AccountId. 
Using that AccountId, I need to retrieve the Account details.
But, I am unable to retrieve it.

Here's my code.
 
import getAccountDetails from "@salesforce/apex/AccountSearch.getAccountDetails";

userId = USER_ID
@track accID

@track accounts;
@track error;
@track errors;
  
@wire(getRecord, {
    recordId: "$userId",
    fields: [ACCOUNT_ID,
            ACCOUNT_NAME]
}) wireuser({error, data}) {
    if (error) {
       this.error = error ; 
    } else if (data) {
        this.accID = data.fields.AccountId.value;
    }
}

//this is not working
@wire (getAccountDetails, {accountId: "$accId"}) wiredAccounts({data, error}){
  if(data) {
    this.accounts =data;
    this.errors = undefined;
  }else {
    this.accounts =undefined;
    this.errors = error;
    console.log("error - "+error);
  }
}
 
public without sharing class AccountSearch {
    @AuraEnabled(cacheable=true)
    public static Account getAccountDetails(String accountId){
        Account accountDetails = [Select id, name, recordtypeid, type FROM Account WHERE id=:accountId];
        return accountDetails;
    }
}

 
Hi,

I have a schedulable apex class that executes method AddRecords.
Method create a new record for object User_Tasks__c for each user account in org. One of the field User_Tasks__c.Total_tasks__c is filled with total tasks count of the user.

I am struggling to write a test class for it.
Sharing code for apex class and test class.
 
global class CreateUserTasks Implements Schedulable{
    global void execute(SchedulableContext sc){
            AddRecords();
    }
    
    public static void AddRecords(){
        List<User> users = [select id,Name from User where IsActive=true];
        Map<Id, Integer> taskCounts = new Map<Id, Integer>();
        List<AggregateResult> ars;
        List<User_Task__c> userTasks= New List<User_Task__c>();
    
        ars = [SELECT  OwnerID owner, count(ID) taskCount FROM Task WHERE OwnerId in (select id from User where IsActive=true) and isClosed = false group by OwnerId];
        
        for(AggregateResult ar : ars) {
            taskCounts.put((ID)ar.get('owner'), Integer.valueOf(ar.get('taskCount')));
            User_Task__c usertask = New User_Task__c();
            usertask.tasks_completed__c = 0;
            usertask.Date__c = System.today();
            usertask.Total_tasks__c = Integer.valueOf(ar.get('taskCount'));
            
        }
        insert userTasks;
        }
}

My test class has 0% test coverage. My test class:
@isTest
private class TestCreateUserTasks{
	static testMethod void validateSampleApex() {
        
		Test.startTest();
        
        User u1 = new user();
        u1.LastName = 'A';
        u1.Email = 'test@test.com';
        u1.Alias = 'A';
        u1.Username = 'A1234444@test.com';
        u1.CommunityNickname = 'A12';
        u1.LocaleSidKey = 'en_US';
        u1.TimeZoneSidKey = 'GMT';
        u1.ProfileID = '00e1C000001J8DbQAK';
        u1.LanguageLocaleKey = 'en_US';
        u1.EmailEncodingKey = 'UTF-8';
        insert u1;
        
        User_Task__c utA = New User_Task__c();
        utA.Date__C = System.today();
        utA.Total_tasks__c = 0;      
        insert utA;
        
        List<Task> tasks = new List<Task>{};

        System.runAs(u1) {
        	Task tA = new Task(Subject='TestA1',Status='New',Priority='Normal',CallType='Outbound');
            insert tA; 
        }
        
        List<User> users = [select id,Name from User where IsActive=true];

        List<User_Task__c> utList= [Select ID From User_Task__c where date__c = :System.today()];
        		
        System.assertEquals(2, utList.size());
        
		Test.stopTest();     
	}
}

Can someone please help me how to test schedulable class with method to insert new records.

Thanks,
Jas
Hi,

I have two objects Account, and abc_and_sale_summary__c. I am trying to implement before update trigger on Account which will update values in abc_and_sale_summary__c.

Account has fields club__c(text), created_date__c, and down_payment__c(text later converted to decimal).
abc_and_sale_summary__c has fields ABC_Down_payment__c, club__c, and date__c.

My trigger on account will update down_payment__c field with value from down_payment__c field.

for example: Account A for club vancouver, date mar 07 has down_payment__c of $100.
Account B for club vancouver, date mar 07 has down_payment__c of $50.
Account C for club vancouver, date mar 07 has down_payment__c of $150.

Trigger will update existing record in abc_and_sale_summary__c for club vancouver and date mar 07. Value of ABC_Down_payment__c should be $300.


Code of update trigger. Right now, it is not updating the ABC_Down_payment__c field. Please help me point out the problem in logic.
List<ABC_and_Sale_Summary__c> abc= New List<ABC_and_Sale_Summary__c>();
    Map<Id, ABC_and_Sale_Summary__c> abcMap= New Map<Id, ABC_and_Sale_Summary__c>();

if(Trigger.isUpdate ){
        ABC_and_Sale_Summary__c abc2= New ABC_and_Sale_Summary__c();
        List<ABC_and_Sale_Summary__c> abc3= New List<ABC_and_Sale_Summary__c>();
        
        abc3 = [Select id, club__c, date__c, sale_Summary_Revenue__c, ABC_Down_payment__c from ABC_and_Sale_Summary__c];

        for(ABC_and_Sale_Summary__c abc_sale: abc3){

        for(integer c = 0; c < Trigger.Old.size(); c++){
            Date d = date.newinstance(Trigger.New[c].created_date__c.year(), Trigger.New[c].created_date__c.month(), Trigger.New[c].created_date__c.day());
	    	Date d2 = date.newinstance(Trigger.Old[c].created_date__c.year(), Trigger.Old[c].created_date__c.month(), Trigger.Old[c].created_date__c.day());
			
            
                if((abc_sale.club__c == Trigger.Old[c].club__c) && (abc_sale.date__c == d2))
				{
                    system.debug(abc_sale.Id);
					String dp = Trigger.New[c].Down_Payment__c;
            
					if(dp.contains('$')){
						dp = dp.substring(1);
					}
					
					Double downpayment = Decimal.valueOf(dp);
            
					
						String dpold = Trigger.Old[c].Down_Payment__c;
						if(dpold.contains('$')){
							dpold = dpold.substring(1);
						}
						
						Double downpaymentold = Decimal.valueOf(dpold);
						
						double diff = downpayment - downpaymentold;
                    	if(abc_sale.ABC_Down_payment__c ==null){abc_sale.ABC_Down_payment__c = 0;}
						abc_sale.ABC_Down_payment__c = abc_sale.ABC_Down_payment__c + diff;
						
						abc.add(abc_sale);
                        
				}	
			}	
        }
        abcMap.putAll(abc);
            update abcMap.values();
    }

this code is working for single insert/update of record. But, it is not working in case of mass upsert.
Hi all,

I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.

What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.

I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page. 
 
From Account: 
select sum(down_payment_received__c) from account where created_date__c > 2018-03-12T00:00:00Z and created_date__c < 2018-03-13T00:00:00Z and Location__c in ('Location A', 'Location B', 'Location C', 'Location D') group by Location__c


This query will give me result for Mar 12 and for all Locations. 

Similarly, For Sales object:
1select Date__c, Location__c, Total_Revenue_End_of_the_day__c from sales__c where Date__c = 2018-03-12

This query will give results for sales object. 

But, what I wanted is use a single query to get results from both objects.

I would like a data such as following (layout could be little different)

Date                     Location            Down Payment            Total Revenue             Total Revenue - Down Payment
2018-03-18           Location A                 100                              100                                           0
2018-03-18           Location B                 150                              100                                          50


Please, let me know how this could be possible. 
Hi everyone,

I have two objects Account and Sales.
Account has fields - name, created date, location, payment made.
Sales has fields - date, location, revenue.

I want to compare sum of all payment made by all accounts group by created date and location with revenue from sales object on particular date for same location.
 
for eg: 5 accounts from location A on Mar 01 has sum of 1000 as payment made.
Also on sales object location A on mar 01 should have revenue greater than 1000 or more.

I have tried reports, but I am not successful in getting it solved.

please suggest me possible ideas which I can use to implement this. I am comfortable using apex if needed.
Hi,

As logged in user to LWC, I need to display user's related Account details on LWC page.
User object has standard field AccountId. 
Using that AccountId, I need to retrieve the Account details.
But, I am unable to retrieve it.

Here's my code.
 
import getAccountDetails from "@salesforce/apex/AccountSearch.getAccountDetails";

userId = USER_ID
@track accID

@track accounts;
@track error;
@track errors;
  
@wire(getRecord, {
    recordId: "$userId",
    fields: [ACCOUNT_ID,
            ACCOUNT_NAME]
}) wireuser({error, data}) {
    if (error) {
       this.error = error ; 
    } else if (data) {
        this.accID = data.fields.AccountId.value;
    }
}

//this is not working
@wire (getAccountDetails, {accountId: "$accId"}) wiredAccounts({data, error}){
  if(data) {
    this.accounts =data;
    this.errors = undefined;
  }else {
    this.accounts =undefined;
    this.errors = error;
    console.log("error - "+error);
  }
}
 
public without sharing class AccountSearch {
    @AuraEnabled(cacheable=true)
    public static Account getAccountDetails(String accountId){
        Account accountDetails = [Select id, name, recordtypeid, type FROM Account WHERE id=:accountId];
        return accountDetails;
    }
}

 
Hi,

I have a schedulable apex class that executes method AddRecords.
Method create a new record for object User_Tasks__c for each user account in org. One of the field User_Tasks__c.Total_tasks__c is filled with total tasks count of the user.

I am struggling to write a test class for it.
Sharing code for apex class and test class.
 
global class CreateUserTasks Implements Schedulable{
    global void execute(SchedulableContext sc){
            AddRecords();
    }
    
    public static void AddRecords(){
        List<User> users = [select id,Name from User where IsActive=true];
        Map<Id, Integer> taskCounts = new Map<Id, Integer>();
        List<AggregateResult> ars;
        List<User_Task__c> userTasks= New List<User_Task__c>();
    
        ars = [SELECT  OwnerID owner, count(ID) taskCount FROM Task WHERE OwnerId in (select id from User where IsActive=true) and isClosed = false group by OwnerId];
        
        for(AggregateResult ar : ars) {
            taskCounts.put((ID)ar.get('owner'), Integer.valueOf(ar.get('taskCount')));
            User_Task__c usertask = New User_Task__c();
            usertask.tasks_completed__c = 0;
            usertask.Date__c = System.today();
            usertask.Total_tasks__c = Integer.valueOf(ar.get('taskCount'));
            
        }
        insert userTasks;
        }
}

My test class has 0% test coverage. My test class:
@isTest
private class TestCreateUserTasks{
	static testMethod void validateSampleApex() {
        
		Test.startTest();
        
        User u1 = new user();
        u1.LastName = 'A';
        u1.Email = 'test@test.com';
        u1.Alias = 'A';
        u1.Username = 'A1234444@test.com';
        u1.CommunityNickname = 'A12';
        u1.LocaleSidKey = 'en_US';
        u1.TimeZoneSidKey = 'GMT';
        u1.ProfileID = '00e1C000001J8DbQAK';
        u1.LanguageLocaleKey = 'en_US';
        u1.EmailEncodingKey = 'UTF-8';
        insert u1;
        
        User_Task__c utA = New User_Task__c();
        utA.Date__C = System.today();
        utA.Total_tasks__c = 0;      
        insert utA;
        
        List<Task> tasks = new List<Task>{};

        System.runAs(u1) {
        	Task tA = new Task(Subject='TestA1',Status='New',Priority='Normal',CallType='Outbound');
            insert tA; 
        }
        
        List<User> users = [select id,Name from User where IsActive=true];

        List<User_Task__c> utList= [Select ID From User_Task__c where date__c = :System.today()];
        		
        System.assertEquals(2, utList.size());
        
		Test.stopTest();     
	}
}

Can someone please help me how to test schedulable class with method to insert new records.

Thanks,
Jas
Hi all,

I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.

What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.

I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page. 
 
From Account: 
select sum(down_payment_received__c) from account where created_date__c > 2018-03-12T00:00:00Z and created_date__c < 2018-03-13T00:00:00Z and Location__c in ('Location A', 'Location B', 'Location C', 'Location D') group by Location__c


This query will give me result for Mar 12 and for all Locations. 

Similarly, For Sales object:
1select Date__c, Location__c, Total_Revenue_End_of_the_day__c from sales__c where Date__c = 2018-03-12

This query will give results for sales object. 

But, what I wanted is use a single query to get results from both objects.

I would like a data such as following (layout could be little different)

Date                     Location            Down Payment            Total Revenue             Total Revenue - Down Payment
2018-03-18           Location A                 100                              100                                           0
2018-03-18           Location B                 150                              100                                          50


Please, let me know how this could be possible. 
Hi everyone,

I have two objects Account and Sales.
Account has fields - name, created date, location, payment made.
Sales has fields - date, location, revenue.

I want to compare sum of all payment made by all accounts group by created date and location with revenue from sales object on particular date for same location.
 
for eg: 5 accounts from location A on Mar 01 has sum of 1000 as payment made.
Also on sales object location A on mar 01 should have revenue greater than 1000 or more.

I have tried reports, but I am not successful in getting it solved.

please suggest me possible ideas which I can use to implement this. I am comfortable using apex if needed.