• Krishna Bandi
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
Hi,

I am getting "Internal Salesforce.com Error" while executing the below SOQL statement

list<CustomObject> calls1MonthList = new list<CustomObject>();
calls1MonthList = [select Id, CreatedById from CustomObject where CreatedById in : 'Passing User Ids' and createdDate>:system.today().addDays(-60) and RecordTypeId =:'record Type ID here'];

I tried it by adding more filters into the query, however it does work for couple of times and again it starts giving me the same error.
Our Org has Person Accounts enabled so what I am trying to do is create a Workflow Rule that fires off an Email Alert.  When creating the Workflow Rule, I have to use the Account object (Person Accounts are a type of Account, not a type of Contact) and when I do that and get to the New Email Alert screen, I then go to the Recipient Type field and select Email Field, but there are no Available Recipients.

That is not a surprise given the standard Business Account object (which the Workflow engine uses) does have an email field.  But, if my Org has Person Accounts enabled shouldn't the Account.PersonEmail field become an Available Receipients option?  Or, maybe there is a different way to approach this?  All ideas welcomed!!!
I am getting this error for a scheduled job that sends mass emails every day.

First error: SendEmail failed. First exception on row 0; first error: LIMIT_EXCEEDED, Too many target object ids.: []

Here is the code:

global with sharing class EmailSenderBatch implements Database.Batchable<SObject>, Database.Stateful 
{
    public String query = '';
    global Set<ID> contactIDsToSendEmailTo;
    
    public EmailSenderBatch()
    {
        query = 'Select ID, Name from Account';
        contactIDsToSendEmailTo = new Set<ID>();
    }   
    
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, list<sObject> scope)
    {
        Set<ID> accountIDs = new Set<ID>();
        for(Account a: (List<Account>) scope)
            accountIDs.add(a.ID);
        
        Set<ID> accountIdsToSendEmailTo = new Set<ID>();
        for(Contract ctrct: [Select ID, AccountID, Subscription_Start_Date__c
                             from Contract 
                             where AccountID in: accountIDs
                             and Contract_Status__c =: 'Active'
                             and Subscription_Start_Date__c !=: null])
        {
        //send every 3 months and 9 months from subscription start date
            if(
            ((ctrct.Subscription_Start_Date__c.addMonths(3).month() == (Date.today().month()))
            || (ctrct.Subscription_Start_Date__c.addMonths(9).month() == (Date.today().month())))
            )
            {
                accountIDsToSendEmailTo.add(ctrct.AccountID);
            }
        }
        
        //if we have qualified accounts
        if(accountIDsToSendEmailTo.size() > 0)
        {
            for(Contact c: [Select ID, LastName, FirstName, Key_Contact__c
                            from Contact
                            where AccountID in: accountIdsToSendEmailTo
                            and Contact_Status__c =: Constants.STATUS_ACTIVE
                            ])
            {
                if(c.Key_Contact__c != null && c.Key_Contact__c.contains(Constants.CONTACTOBJ_PRIMARY_SUPPORT_CONTACT))
                    contactIDsToSendEmailTo.add(c.ID);
            }
        }
    }
    
    global void finish(Database.BatchableContext BC)
    {
        if(contactIDsToSendEmailTo.size() > 0)
        {
            List<ID> contactIDs = new List<ID>();
            contactIDs.addAll(contactIDsToSendEmailTo);
            Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
            mail.setSenderDisplayName('Andrew Simpson');
            mail.setTargetObjectIds(contactIDs);
            mail.setTemplateId(GenericServices.getGeneralSettingValueForKey(Constants.TEMPLATE_ID));
            Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
        }
    }
    
    global static void startCalculation()
    {
        EmailSenderBatch cesb = new EmailSenderBatch();
        Database.executeBatch(cesb);
    }
}

Is the error referring to the daily email limit or too many results from the query? Any help on how I could resolve the limit would be appreciated.
  • June 02, 2014
  • Like
  • 0
Hi,

I am getting "Internal Salesforce.com Error" while executing the below SOQL statement

list<CustomObject> calls1MonthList = new list<CustomObject>();
calls1MonthList = [select Id, CreatedById from CustomObject where CreatedById in : 'Passing User Ids' and createdDate>:system.today().addDays(-60) and RecordTypeId =:'record Type ID here'];

I tried it by adding more filters into the query, however it does work for couple of times and again it starts giving me the same error.

I want to add a button on edit page of a record (say button which opens an external URL in a new window, may be a a url for reference). How do I achieve so?


There's always option of overriding with visualforce page, but there's lot of pitfalls around that approach (say a new recordtype or field is added, you need to create new visualforcce page or update the page respectively etc)

Any idea on how to achieve this? 

 

Chirag