• Max H. Goldfarb
  • NEWBIE
  • 30 Points
  • Member since 2019


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 14
    Replies

Hi all,

i'm trying to figure it out what I'm doing wrong here, when I'm looking for my Debog Logs I see this error:

User-added imageUser-added imageand my part of code where is the error.

Can anyone help me with this error?

I am trying to send an email while using PageReference and the getContent() method which is, only ocassionally, throwing an error (seems like every couple of emails regardless of the frequency). According to the docs, the getContent() method cannot be used in Apex email services.

When I do not invoke any email service my code works as expected 100% of the time, however it seems like when I attempt to send an email in the same context of when I use my getContent() method, an underlying SFDC bug occasionally is throwing the error: "FATAL_ERROR System.VisualforceException: null."

I have tried a lot of workarounds, including future methods, posting chatter feed posts to groups with emails on for every post, using a batch class and sending the email in the finish context, and a few other things but to no avail. I am hoping someone may have some ideas or can help lead me in the right direction. My code is below, thanks!
 
global class emailDeliverabilityStatus implements Schedulable {
    global void execute(SchedulableContext ctx) {
        PageReference pr = new PageReference(Url.getSalesforceBaseUrl().toExternalForm() + '/email-admin/editOrgEmailSettings.apexp');
        Blob statusCheck = pr.getContent();
        Email_Status__c	status = Email_Status__c.getall().values()[0];
        if (statusCheck != null && statusCheck.toString().contains('All email')) {
            status.deliverability_on__c = true;
            status.time_changed__c = system.now();
            List<String> sendTo = status.email_list__c.split(',');
            //Calls future method that sends the email to notify users
            sendEmailDelivNotification.sendEmail(sendTo, status.time_changed__c);
        } else if (statusCheck != null) {
            status.deliverability_on__c = false;
            status.time_changed__c = system.now();
        }
        update status;
    }
}

 
Hey guys,

I imported a bunch of records to an object.

Now the record owner is set to 'Data Import' - a custom user for data import so I know which are imported and which are not.

Each record has a lookup to Account. I want to change the record ownership of the imported records to the owner of the related Account.

This sounds quite simple, just execute anonymous apex via console, before that I should make a backup and so on.

But I wonder what is the cleanest apex code for such update of record ownership? How would you do it?

Thanks
Jan
Hi

I am updating the AccountContactRelation Object Record from external user.I am getting this error.But for admin everything is working fine

Hi my friends, 

I am trying to store more than 60,000 record from Batch apex result, and I have to edit the record with schedulable apex every 5 mins. 


So, 
Can I store this data in a global variable? I googled it, but all I can find was for Normal global variable. 

Would you be able to direct me to the link or show me a simple code line please? 


Thank you :)

 

Hi all,

i'm trying to figure it out what I'm doing wrong here, when I'm looking for my Debog Logs I see this error:

User-added imageUser-added imageand my part of code where is the error.

Can anyone help me with this error?

Hi i'm lost in a test for a send email, i need to test if the email as sent, how i do that?

Thanks for your attention

Batch Class:
global class EmailCaringSenior implements Schedulable, Database.Batchable<sObject> {
    
    Account estipulante;
    
	global Database.QueryLocator start(Database.BatchableContext BC) {
        try{
        	estipulante = [SELECT Id FROM Account WHERE RecordTypeId IN (SELECT Id FROM RecordType WHERE Name = 'Estipulante' AND SObjectType = 'Account') AND Name = 'Caring Senior'];
        } catch(Exception e) {
             System.debug('The following exception has occurred: ' + e.getMessage());
        }
        return Database.getQueryLocator([SELECT Name, CPF__pc FROM Account WHERE Estipulante__c = :estipulante.Id AND CreatedDate = TODAY]);
	}
    
   	global void execute(Database.BatchableContext BC, List<sObject> scope) {
		List<Account> accounts = (List<Account>) scope;
        String listaPaciente = '';
        Integer contagem = 0;
		for(Account paciente : accounts){
			contagem++;
            listaPaciente +=  contagem + '. ' + paciente.Name + ' (CPF: ' + paciente.CPF__pc + ') <br>';
		}
        
		String dataOntem = DateTime.now().addDays(-1).format('dd-MM-yyyy');
        
		Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.toAddresses = new String[] { 'gabrielmocelin@unochapeco.edu.br' };
        message.subject = 'Ace - Novos Pacientes (' + dataOntem +  ')';
        message.setHtmlBody('Olá Gestor, <br> Abaixo uma lista de pacientes carregados no Health Cloud ontem (' + dataOntem + '): <br><br> ' + listaPaciente);
        for(OrgWideEmailAddress owa : [SELECT Id, Address, DisplayName FROM OrgWideEmailAddress]) 
        {
           if(owa.DisplayName.contains('Caring Senior'))
           { 
            message.setOrgWideEmailAddressId(owa.Id); 
           } 
        }
        Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
        
        if (results[0].success) 
        {
            System.debug('The email was sent successfully.');
        } else 
        {
            System.debug('The email failed to send: ' + results[0].errors[0].message);
        }
    }

	global void execute(SchedulableContext sc) {
		EmailCaringSenior b = new EmailCaringSenior();
		Database.executebatch(b);
	}
	
	global void finish(Database.BatchableContext BC) {
		
	}
}
Test Class:
@isTest
public class Test_EmailCaringSenior {
    
    static testMethod void testInsertDetecta()
    {   
        Integer contasAntes = [SELECT COUNT() FROM Account];
        System.assertEquals(contasAntes, 0);
        
        RecordType estipulanteRecordType = [SELECT Id FROM RecordType WHERE Name = 'Estipulante' AND SObjectType = 'Account'];
        Account estipulante = new Account();
        estipulante.RecordTypeId = estipulanteRecordType.Id;             
        estipulante.Name = 'Caring Senior';
        insert estipulante;
        
        Datetime dataAnteOntem = Datetime.now().addDays(-2);
        Test.setCreatedDate(estipulante.Id, dataAnteOntem);
 
        RecordType personAccountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Paciente' AND SObjectType = 'Account'];
        Account paciente = new Account();
        paciente.RecordType = personAccountRecordType;             
        paciente.FirstName = 'Teste';
        paciente.LastName = 'Sobrenome';
        paciente.CPF__pc = '133.173.513-06';
        paciente.Estipulante__c = estipulante.id;
        insert paciente;
        
        Datetime dataOntem = Datetime.now().addDays(-1);
        Test.setCreatedDate(paciente.Id, dataOntem);

        Test.startTest();
			Account myAccount = [SELECT Id, Name, CreatedDate FROM Account WHERE Name ='Teste Sobrenome' LIMIT 1];
        	System.assertEquals(myAccount.CreatedDate, dataOntem);	
      		
           	Account estipulanteTest = [SELECT Id, CreatedDate FROM Account WHERE Name = 'Caring Senior' AND RecordTypeId = :estipulanteRecordType.Id];
			System.assertEquals(estipulanteTest.Id, estipulante.id);
        	System.assertEquals(estipulanteTest.CreatedDate, dataAnteOntem);
        
            EmailCaringSenior b = new EmailCaringSenior();
			Database.executebatch(b);
        
        Test.stopTest();
    }
}

 

For some reason in the Developer Console the Tests tab seems to stop displaying new test results after 4 runs.  Anyone else noticed the problem?  I'm wondering if there's a menu entry somewhere that lets me to clear the tab, but not finding any.  It'd be handy not just for when it's stuck, but also when my result list grows too long.  Any suggestion is appreciated.