• sfAdmin Banjo
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Desperately needing some help here! 

I have a batch class that sends an email to a lead owner based on the Status not changing during a specified timeframe. I manually tested it (without the time query filter) and the code was doing what it needs to do. I've now written the test code only to find the Leadhistory query returns an null record set. I can see the Leads have an ID and I perform some status updates on the test method to generate the LeadHistory records so im clueless as to why it is not returning any records.

test method:
@isTest
private class LeadStatusBatchTest {
	
	@isTest static void test_method_one() {
		// First Load some Leads from resource file
		List<sObject> leads = Test.loadData(Lead.sObjectType, 'Default_Lead_Test_Data');
		system.debug('### [LeadStatusBatchTest] leads (loaded test data): '+ leads);

		//set a datetime to 4 weeks ago to update createdDate
		Datetime weeksAgo_4 = Datetime.now().addDays(-28);
		
		for(Lead ld: (List<Lead>)leads) {
			//update the status and save to DB
			ld.Status = 'Open';
			Test.setCreatedDate(ld.Id, weeksAgo_4.addDays(-7));
		} 
		
		update leads; //to generate a leadHistory entry for Open status
		system.debug('### [LeadStatusBatchTest] Updated CreatedDate on Leads: '+ [Select id, CreatedDate From Lead where Id = :leads]);

		//validate update worked
		for(lead ld: [select id, status, createdDate From Lead where id in : leads]){
			system.assertEquals('Open', ld.Status);
			system.assertEquals(weeksAgo_4.addDays(-7), ld.CreatedDate);
		}

		//get the leadhistory records and update their createddate to same as lead created date
		for(LeadHistory lh: [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]){
			Test.setCreatedDate(lh.id, weeksAgo_4.addDays(-7));
		}
		system.debug('### [LeadStatusBatchTest] LeadHistory testdata: '+ [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]);

		//update Status to Contacted
		for(lead ld: (List<Lead>)leads){
			ld.Status = 'Contacted';
		}
		update leads;
		
		//get LeadHistory for Lead and update the CreatedDate
		for(LeadHistory lh: [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]){
			if(lh.newvalue == 'Contacted')
				Test.setCreatedDate(lh.id, weeksAgo_4);
		}
		system.debug('### [LeadStatusBatchTest] leadHistory Contacted status: '+ [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]);

		//validate LeadHistory CreatedDate
		for(LeadHistory lh: [select id, CreatedDate from LeadHistory where LeadId =: leads]){
			system.assertEquals(weeksAgo_4, lh.CreatedDate);
		}

		test.startTest();
			//run batch class
			LeadStatusBatch db = new LeadStatusBatch();
			database.executeBatch(db);
		test.stopTest();
		system.debug('### [LeadStatusBatchTest] Stopped Test. ');
		
		//make validations if execution was successful


	}
	
	
}

When I run the test the test method debugs return a null data set on the LeadHistory query that is supposed to set the CreatedDate. All queries before that work just fine.

Is it that you cant query hte LeadHistory table on a testmethods? (doesnt seem right)
Or that changes to the lead are not tracked in LeadHistory?

Any help here would be much appreciated! 
 
Hello, I got what must be a simple issue but for which I cannot get a solution : 
I have a custom object for which I am loading a list of records in a VF page. I get the list of fields from a Conga Query string by parsing the field names and building a list of field names, I then reference this list in a repeat component inside a pageblocktable but I get the following Error:

Exception: Invalid field Effective_Date__c for SObject loan__Repayment_Schedule__c 

The VF page code is:
<apex:pageblocksection title="repayment Schedule" columns="1">
            <apex:pageBlockTable value="{!schedule}" var="sched">
                <apex:repeat value="{!schedFields}" var="fld">
                    <apex:column value="{!sched[fld]}"/>
                </apex:repeat>
            </apex:pageBlockTable>
        </apex:pageblocksection>

And the controller code is the following:
public with sharing class LoanAgreementConfigController {
    private loan__loan_account__c loan;
    private String schedQuery;
    public String[] schedFields {get;set;}

    public loan__Repayment_Schedule__c [] schedule {
        get{
            if(schedule == null)
                schedule = getRepaymentSchedule();
            return schedule;
        }
        private set;
    }
    
    
    public LoanAgreementConfigController(ApexPages.StandardController controller) {
         this.loan = (loan__loan_account__c)controller.getRecord();
         //FIRST GET ALL QUERY STRINGS FROM CONGA QUERIES:
         schedFields = new String []{};
         getAllCongaQueryStrings();
    }
    
    private loan__Repayment_Schedule__c[] getRepaymentSchedule() {
        return database.query(schedQuery);
    }

    //this method queries the Conga Query table to get all query strings used in the Send Loan Agreement button, this will allow 
    //the query to be updated via Conga without disrupting this page.
    private void getAllCongaQueryStrings(){
        try {
            map<string,APXTConga4__Conga_Merge_Query__c> congaQueriesMap = new map<string,APXTConga4__Conga_Merge_Query__c> ();

            for(APXTConga4__Conga_Merge_Query__c congaquery: [Select id, APXTConga4__Name__c, APXTConga4__Query__c From APXTConga4__Conga_Merge_Query__c]){
                String recName = congaquery.APXTConga4__Name__c;
                String queryStr = congaquery.APXTConga4__Query__c.substringBefore('WHERE');
                if(recName == 'AmortizationSchedule'){
                    schedQuery = queryStr + 'WHERE loan__Loan_Account__c =\'' + loan.id + '\' ORDER BY loan__Due_Date__c ASC';
                    congaQueriesMap.put(recName, congaquery);
                    schedFields = congaquery.APXTConga4__Query__c.substringBefore('FROM').removeStart('SELECT').split(',');
                }
            }           
        }catch (Exception e) {
		
        }
    }
}

Please mind the missing code as this is a bare bones page as I just started it, so no exception handling yet. Hopeful;ly someone can shed a light into what im missing here!!!

 
Hello,

I have the following parsed code from a WDSL file, it is for a web service from Payment Adviser. 
public class BasicHttpBinding_IRemittanceService {
       
        public String endpoint_x;
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'PaymentAdviser.com.au', 'paymentadviserComAu', 'http://schemas.microsoft.com/2003/10/Serialization/', 'schemasMicrosoftCom200310Serializat', 'http://schemas.datacontract.org/2004/07/PaymentAdviser.Framework.WcfContract.CreditFactoring', 'schemasDatacontractOrg200407Payment'};
I tried adding the username and the password into the inputhttpHeaders_x since there is no revelant username or password variable to input this info into, as follows:
paymentadviserComAu.BasicHttpBinding_IRemittanceService serv = new paymentadviserComAu.BasicHttpBinding_IRemittanceService(); //the callout service class
            serv.endpoint_x  = pay.Enpoint__c;
            Map<String,String> myHeaders = new Map<String,String> ();         
            myHeaders.put('UserName',pay.Username__c);
            myHeaders.put('Password',pay.Password__c );
            serv.inputHttpHeaders_x = myHeaders;
            serv.UploadRemittanceXml(xmlbody);
when I run it I get the following error:

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: An error occurred when verifying security for the message. faultcode=a:InvalidSecurity faultactor=

Not sure how to get the username and password header in the callout, I checked and there is no class, method or variable in the class for security credentials, so im a bit lost.





 
Desperately needing some help here! 

I have a batch class that sends an email to a lead owner based on the Status not changing during a specified timeframe. I manually tested it (without the time query filter) and the code was doing what it needs to do. I've now written the test code only to find the Leadhistory query returns an null record set. I can see the Leads have an ID and I perform some status updates on the test method to generate the LeadHistory records so im clueless as to why it is not returning any records.

test method:
@isTest
private class LeadStatusBatchTest {
	
	@isTest static void test_method_one() {
		// First Load some Leads from resource file
		List<sObject> leads = Test.loadData(Lead.sObjectType, 'Default_Lead_Test_Data');
		system.debug('### [LeadStatusBatchTest] leads (loaded test data): '+ leads);

		//set a datetime to 4 weeks ago to update createdDate
		Datetime weeksAgo_4 = Datetime.now().addDays(-28);
		
		for(Lead ld: (List<Lead>)leads) {
			//update the status and save to DB
			ld.Status = 'Open';
			Test.setCreatedDate(ld.Id, weeksAgo_4.addDays(-7));
		} 
		
		update leads; //to generate a leadHistory entry for Open status
		system.debug('### [LeadStatusBatchTest] Updated CreatedDate on Leads: '+ [Select id, CreatedDate From Lead where Id = :leads]);

		//validate update worked
		for(lead ld: [select id, status, createdDate From Lead where id in : leads]){
			system.assertEquals('Open', ld.Status);
			system.assertEquals(weeksAgo_4.addDays(-7), ld.CreatedDate);
		}

		//get the leadhistory records and update their createddate to same as lead created date
		for(LeadHistory lh: [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]){
			Test.setCreatedDate(lh.id, weeksAgo_4.addDays(-7));
		}
		system.debug('### [LeadStatusBatchTest] LeadHistory testdata: '+ [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]);

		//update Status to Contacted
		for(lead ld: (List<Lead>)leads){
			ld.Status = 'Contacted';
		}
		update leads;
		
		//get LeadHistory for Lead and update the CreatedDate
		for(LeadHistory lh: [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]){
			if(lh.newvalue == 'Contacted')
				Test.setCreatedDate(lh.id, weeksAgo_4);
		}
		system.debug('### [LeadStatusBatchTest] leadHistory Contacted status: '+ [select id, oldvalue, newvalue from LeadHistory where LeadId =: leads]);

		//validate LeadHistory CreatedDate
		for(LeadHistory lh: [select id, CreatedDate from LeadHistory where LeadId =: leads]){
			system.assertEquals(weeksAgo_4, lh.CreatedDate);
		}

		test.startTest();
			//run batch class
			LeadStatusBatch db = new LeadStatusBatch();
			database.executeBatch(db);
		test.stopTest();
		system.debug('### [LeadStatusBatchTest] Stopped Test. ');
		
		//make validations if execution was successful


	}
	
	
}

When I run the test the test method debugs return a null data set on the LeadHistory query that is supposed to set the CreatedDate. All queries before that work just fine.

Is it that you cant query hte LeadHistory table on a testmethods? (doesnt seem right)
Or that changes to the lead are not tracked in LeadHistory?

Any help here would be much appreciated!