• Jan Staufenberg
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Dear all,

I am trying to override the "Accept"-Button on a Custom-Object. Bizarrely only the pages that are using StandardControllers appear when trying to select a custom Visualforce Page and NOT the ones utilizing a StandardSetController. I want to know the Ids the User selected, which is not possible with a StandardController related page, because "ids"-Parameter of the form passed to the custom page (retrieved by ApexPages.CurrentPage().getParameters() only contains the Id of the first selected record.
If I build a page using StandardController, assign it as the override page for the "Accept"-Button, then change the page afterwards including the recordSetVar-attribute to the page, I am able to retrieve the records, but I bet I will not be able to deploy the override this way.

I assume this is a bug, as the StandardSetController makes a lot more sense...
Please help!

Thanks & regards,
Jan
Hi all,
I'm facing problems on accessing values of an object I passed to Database.executeBatch() method in a test class.
The following code sample is my Batchable Apex Class for sending eMails:
public without sharing class EmailHandler implements Schedulable, Database.batchable<Attachment>, Database.AllowsCallouts, Database.Stateful {
	
	/* Contains the total number of sent eMails for the last executed run */
	private Integer SentMailsLastRun;
	
	/* Constructs the eMail-Handler, initializing the count of eMails that have been sent during this run */
	public EmailHandler() {
		//Initialize count of sent mails for this run
		SentMailsLastRun = 0;
	}
	
	/*
	 * Starts the batch processing of attachments, collecting all attachments to process.
	 */
    public Iterable<Attachment> start(Database.BatchableContext BC){
       System.debug(LoggingLevel.INFO,'EmailHandler.start: Reading attachments to process in batch...');
       List<Attachment> attachmentList = processAttachments();
       if(attachmentList!=null) {
       	System.debug(LoggingLevel.INFO,'EmailHandler.start: Collected ' + attachmentList.size() + ' Attachments to process in batch-execution.');
       } else {
       	System.debug(LoggingLevel.INFO,'EmailHandler.start: No Attachments to process in batch-execution.');
       }
       if(attachmentList == null){
       		attachmentList = new List<Attachment>();	 
       }
       return attachmentList;
    }
    
    /*
     * Executes the eMail sending for a given batch of attachments. 
     */
    public void execute(Database.BatchableContext BC, List<Attachment> attachmentList){
       if(attachmentlist != null && attachmentList.size() > 0){
       		System.debug(LoggingLevel.INFO,'EmailHandler.execute: Batch execution started. Batch Size: ' + attachmentList.size());
       		emailServiceWorkOrder(attachmentList);
       		System.debug(LoggingLevel.INFO,'EmailHandler.execute: Batch processing of ' + attachmentList.size() + ' Attachments finished.');
       }else{
       	  System.debug(LoggingLevel.INFO,'EmailHandler.execute: No Attachments to process in this batch.');
       } 
    }

    /*
     * Is called after batch processing is finished.
     */
    public void finish(Database.BatchableContext BC){
    	 System.debug(LoggingLevel.INFO,'EmailHandler.finish: Batch execution finished.');
    }
    
    /*
     * Is called from system when its time to execute the planned job.
     */
    public void execute(SchedulableContext SC) {
    	System.debug(LoggingLevel.INFO,'EmailHandler.execute(SchedulableContext SC): Scheduled Job execution started.');
        EmailHandler emailhandler = new EmailHandler();
        Database.executebatch(emailhandler, 100);
        System.debug(LoggingLevel.INFO,'EmailHandler.execute(SchedulableContext SC): Batch execution triggered.');
    }

    /* Returns the number of mails sent the last run, if execution is still running returns -1 */
    public Integer getSentMails() {
        return SentMailsLastRun;
    }

    /*
     * Collects the attachments for Work Orders in status 'Closed' that have been modified after the last run time of the job.
     */
	private List<Attachment> processAttachments(){
		
[...] collecting of attachments [...]
		
		return attachmentList;
	}

	/*
	 * Processes the attachments passed over: Sends the attachments configured in 'BBMAG_Email_Notification_Settings__c' as 'Service Report Name'
	 * to the addresses configured in the Work Order.
	 */
	private void emailServiceWorkOrder(List<Attachment> newList){

			[...] preparing of eMail-Messages [...]

		//Send Emails
		if (messagesList.size() > 0){
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: Total Emails to be sent: ' + messagesList.size());
			Messaging.sendEmail(messagesList);
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: ' + messagesList.size() + ' Email sent.');
			SentMailsLastRun += messagesList.size();
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: In this run ' + getSentMails() + ' Emails have been sent in total.');
		}
	}
This is how I call Database.executeBatch() from Test-Class:
EmailHandler emailhandler = new EmailHandler();
        Test.StartTest();
        Database.executebatch(emailhandler);
        Test.StopTest();
        
        System.assertEquals(2,emailhandler.getSentMails(),'The expected count of eMails that should\'ve been sent did not match');

The log-output shows, that the variable "SentMailsLastRun" of the EmailHandler-Object has been set correctly and is read correctly from within the class by method getSentMails():
16:47:34:307 USER_DEBUG [521]|INFO|EmailHandler.emailServiceWorkOrder: In this run 2 Emails have been sent in total.
16:47:34:340 EXCEPTION_THROWN [35]|System.AssertException: Assertion Failed: The expected count of eMails that should've been sent did not match: Expected: 2, Actual: 0
Nevertheless, if the method is called from the test-class it delivers the value that has been set by the constructor (0). Does Database.executeBatch() clone the passed object and continues working with the clone?!
How may I access data collected during this process afterwards (Like in my case totally sent eMails) to verify the correctness?

Thanks in advance!
Hi all,
I'm facing problems on accessing values of an object I passed to Database.executeBatch() method in a test class.
The following code sample is my Batchable Apex Class for sending eMails:
public without sharing class EmailHandler implements Schedulable, Database.batchable<Attachment>, Database.AllowsCallouts, Database.Stateful {
	
	/* Contains the total number of sent eMails for the last executed run */
	private Integer SentMailsLastRun;
	
	/* Constructs the eMail-Handler, initializing the count of eMails that have been sent during this run */
	public EmailHandler() {
		//Initialize count of sent mails for this run
		SentMailsLastRun = 0;
	}
	
	/*
	 * Starts the batch processing of attachments, collecting all attachments to process.
	 */
    public Iterable<Attachment> start(Database.BatchableContext BC){
       System.debug(LoggingLevel.INFO,'EmailHandler.start: Reading attachments to process in batch...');
       List<Attachment> attachmentList = processAttachments();
       if(attachmentList!=null) {
       	System.debug(LoggingLevel.INFO,'EmailHandler.start: Collected ' + attachmentList.size() + ' Attachments to process in batch-execution.');
       } else {
       	System.debug(LoggingLevel.INFO,'EmailHandler.start: No Attachments to process in batch-execution.');
       }
       if(attachmentList == null){
       		attachmentList = new List<Attachment>();	 
       }
       return attachmentList;
    }
    
    /*
     * Executes the eMail sending for a given batch of attachments. 
     */
    public void execute(Database.BatchableContext BC, List<Attachment> attachmentList){
       if(attachmentlist != null && attachmentList.size() > 0){
       		System.debug(LoggingLevel.INFO,'EmailHandler.execute: Batch execution started. Batch Size: ' + attachmentList.size());
       		emailServiceWorkOrder(attachmentList);
       		System.debug(LoggingLevel.INFO,'EmailHandler.execute: Batch processing of ' + attachmentList.size() + ' Attachments finished.');
       }else{
       	  System.debug(LoggingLevel.INFO,'EmailHandler.execute: No Attachments to process in this batch.');
       } 
    }

    /*
     * Is called after batch processing is finished.
     */
    public void finish(Database.BatchableContext BC){
    	 System.debug(LoggingLevel.INFO,'EmailHandler.finish: Batch execution finished.');
    }
    
    /*
     * Is called from system when its time to execute the planned job.
     */
    public void execute(SchedulableContext SC) {
    	System.debug(LoggingLevel.INFO,'EmailHandler.execute(SchedulableContext SC): Scheduled Job execution started.');
        EmailHandler emailhandler = new EmailHandler();
        Database.executebatch(emailhandler, 100);
        System.debug(LoggingLevel.INFO,'EmailHandler.execute(SchedulableContext SC): Batch execution triggered.');
    }

    /* Returns the number of mails sent the last run, if execution is still running returns -1 */
    public Integer getSentMails() {
        return SentMailsLastRun;
    }

    /*
     * Collects the attachments for Work Orders in status 'Closed' that have been modified after the last run time of the job.
     */
	private List<Attachment> processAttachments(){
		
[...] collecting of attachments [...]
		
		return attachmentList;
	}

	/*
	 * Processes the attachments passed over: Sends the attachments configured in 'BBMAG_Email_Notification_Settings__c' as 'Service Report Name'
	 * to the addresses configured in the Work Order.
	 */
	private void emailServiceWorkOrder(List<Attachment> newList){

			[...] preparing of eMail-Messages [...]

		//Send Emails
		if (messagesList.size() > 0){
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: Total Emails to be sent: ' + messagesList.size());
			Messaging.sendEmail(messagesList);
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: ' + messagesList.size() + ' Email sent.');
			SentMailsLastRun += messagesList.size();
			System.debug(LoggingLevel.INFO,'EmailHandler.emailServiceWorkOrder: In this run ' + getSentMails() + ' Emails have been sent in total.');
		}
	}
This is how I call Database.executeBatch() from Test-Class:
EmailHandler emailhandler = new EmailHandler();
        Test.StartTest();
        Database.executebatch(emailhandler);
        Test.StopTest();
        
        System.assertEquals(2,emailhandler.getSentMails(),'The expected count of eMails that should\'ve been sent did not match');

The log-output shows, that the variable "SentMailsLastRun" of the EmailHandler-Object has been set correctly and is read correctly from within the class by method getSentMails():
16:47:34:307 USER_DEBUG [521]|INFO|EmailHandler.emailServiceWorkOrder: In this run 2 Emails have been sent in total.
16:47:34:340 EXCEPTION_THROWN [35]|System.AssertException: Assertion Failed: The expected count of eMails that should've been sent did not match: Expected: 2, Actual: 0
Nevertheless, if the method is called from the test-class it delivers the value that has been set by the constructor (0). Does Database.executeBatch() clone the passed object and continues working with the clone?!
How may I access data collected during this process afterwards (Like in my case totally sent eMails) to verify the correctness?

Thanks in advance!
I am new to Lightning app development. I tried "Hello world" sample app given in salesforce quick start guide (https://developer.salesforce.com/resource/pdfs/Lightning_QuickStart.pdf). I first created the App and I was able to preview in browser successfully but when I embedded component into the app then "URL No Longer Exists" error was thrown. I have followed same steps given in the guide but not sure why it is not working. Any help is appreciated.


 

Why won't this SOQL query work?

 

Case tmpCase = [select Id from Case where IsClosed = true and OwnerId like '00G' limit 1];

 

I am trying to get a particular type of Case in a test class.  The compiler complains whenever I put in the LIKE expression.

 

If this won't work, any suggestions on how to do it?

 

Thanks.

I'm following the documentation on updating an object with a relationship field, but I'm getting an error. The documentation says to format the xml as such when referring to a relationship field:

 

<RelationshipName>
  <sObject>
    <IndexedFieldName>rwilliams@salesforcesample.com</IndexedFieldName>
  </sObject>
</RelationshipName>

 

In my case the xml looks something like this:

 

 

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
  <sObject>
    <location_external_id__c>1234</location_external_id__c>
    <Name>My Location</Name>
    <Account__r>
      <sObject>
        <account_external_id__c>7890</account_external_id__c>
      <sObject>
    </Account__r>
  </sObject>
</sObjects>

 

This is an attempt to upsert to a custom object (Location__c) with an external id api name of 'location_external_id__c' that has a text field called 'name' and a Master-Detail(Account) field with relationship name 'Account__r'.  Account has an external id field called account_external_id. As far as I can tell this is all following the documentation for the bulk api. However I get back an error like this:

 

<results xmlns="http://www.force.com/2009/06/asyncapi/dataload">
  <result>
    <errors>
      <fields>Account__r</fields>
      <fields>sObject</fields>
      <fields>account_external_id__c</fields> 
      <message>Location__c: bad field names on insert/update call: Account_r, sObject, account_external_id__c</message>
      <statusCode>INVALID_FIELD_FOR_INSERT_UPDATE</statusCode>
    </errors>
    <success>false</success>
    <created>true</created>
  </result>
</results>

 

This looks to me like the Bulk API doesn't know anything about relationship fields despite what the documentation clearly says. Hopefully I'm just doing something wrong, does anyone have any ideas?