• Roelof Wal
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
I have attached a flow to the opportunity product create/edit stage. 
This works very nice but now I want to use the Quote object too and this means that products from a quote can be synchronised from the Quote to the Opportunity and this will also trigger the opportunity product flow. 
Since this breaks a few things in my setup I would like to detect if the products on the opportunity where added by a user or by the Quote-Opportunity sync "tool". 
Is this possible in any way? 
I have the following code:
public with sharing class getCustomvalues {

        public final Account account;
        public List<String> myitems {get; set;}
        public List<Custom_items__c> myResult {get;set;}
    
        public getCustomvalues() {
            Id id = ApexPages.currentPage().getParameters().get('id');
            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];
            myitems = new List<String>();
            if (account.items__c== null) {
                 myResult =null;  
                //System.debug(LoggingLevel.ERROR, 'result will be empty');
            } else {
                myitems.addAll(account.items__c.split(';'));
System.debug('myResult Query=select Name,Sn__c,Rn__c from Custom_items__c where Name in '+myitems+' order by Ordering_number__c');
                   myResult =[select Name,Sn__c,Rn__c from Custom_items__c where Name in :myitems order by Ordering_number__c];
            }
        }

        public Account getAccount() {
        
            return account;
        }
}
I wrote a test class that works good, but for some reason the myResult object stays empty.
Looking at the test logs I see that  (account.items__c== null) { is not true during the test, so it goes to the } else { section and there myitems is filled and contains data. 

One thing I noticed was that the debug log showed the following for the query
select Name,Sn__c,Rn__c from Custom_items__c where Name in (thevalue) order by Ordering_number__c
This looks wrong because it should be
select Name,Sn__c,Rn__c from Custom_items__c where Name in ('thevalue') order by Ordering_number__c
So instead of (thevalue) it should be ('thevalue') to be correct. 
On the other hand, the code works correct in the normal situations. 


 
I have a custom class which needs testing but I have no clue how to and where to get started. 
Below is an example of the original. 
This code is used on a custom Apex page to generate some output.
public with sharing class getCustomvalues {

		private final Account account;
    	public List<String> myitems {get; private set;}
    	
    	public List<Account_items__c> result {get;set;}
    
    	public getCustomvalues() {
            Id id = ApexPages.currentPage().getParameters().get('id');
            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];
            myitems = new List<String>();
            if (account.items__c== null) {
			    /*
					code
				*/
            } else {
			    /*
					code
				*/
            }
        }

        public Account getAccount() {
        
    	    return account;
	    }

}

My questions:
  1. How to instantiate this class from a testing class?
  2. How to set the currentPage Id ?
    1. Should I use a stub class too?
I have the following code:
public with sharing class getCustomvalues {

        public final Account account;
        public List<String> myitems {get; set;}
        public List<Custom_items__c> myResult {get;set;}
    
        public getCustomvalues() {
            Id id = ApexPages.currentPage().getParameters().get('id');
            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];
            myitems = new List<String>();
            if (account.items__c== null) {
                 myResult =null;  
                //System.debug(LoggingLevel.ERROR, 'result will be empty');
            } else {
                myitems.addAll(account.items__c.split(';'));
System.debug('myResult Query=select Name,Sn__c,Rn__c from Custom_items__c where Name in '+myitems+' order by Ordering_number__c');
                   myResult =[select Name,Sn__c,Rn__c from Custom_items__c where Name in :myitems order by Ordering_number__c];
            }
        }

        public Account getAccount() {
        
            return account;
        }
}
I wrote a test class that works good, but for some reason the myResult object stays empty.
Looking at the test logs I see that  (account.items__c== null) { is not true during the test, so it goes to the } else { section and there myitems is filled and contains data. 

One thing I noticed was that the debug log showed the following for the query
select Name,Sn__c,Rn__c from Custom_items__c where Name in (thevalue) order by Ordering_number__c
This looks wrong because it should be
select Name,Sn__c,Rn__c from Custom_items__c where Name in ('thevalue') order by Ordering_number__c
So instead of (thevalue) it should be ('thevalue') to be correct. 
On the other hand, the code works correct in the normal situations. 


 
I have a custom class which needs testing but I have no clue how to and where to get started. 
Below is an example of the original. 
This code is used on a custom Apex page to generate some output.
public with sharing class getCustomvalues {

		private final Account account;
    	public List<String> myitems {get; private set;}
    	
    	public List<Account_items__c> result {get;set;}
    
    	public getCustomvalues() {
            Id id = ApexPages.currentPage().getParameters().get('id');
            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];
            myitems = new List<String>();
            if (account.items__c== null) {
			    /*
					code
				*/
            } else {
			    /*
					code
				*/
            }
        }

        public Account getAccount() {
        
    	    return account;
	    }

}

My questions:
  1. How to instantiate this class from a testing class?
  2. How to set the currentPage Id ?
    1. Should I use a stub class too?