• Allan Hotchkiss 4
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hello,

I've created a batch job where I am updating some Account records.  In the job I am trying to run a Database.update call passing false as the 2nd parameter to enable saving of successful records even if some of them fail.  The problem I am having is that when 1 of the records fails due to a validation error, it is throwing an exception and not saving the rest of the records.  The documentation states this should not occur and that instead the records that didn't fail should be saved and the failed records be returned from the method call in a Database.SaveResult[] array.What is even stranger is that I have wrapped the Database.update call in a try..catch block and the exception isn't even caught.  I am thinking there is a bug somewhere in the platform causing this not to work as it previously used to.  Here is the code for the execute method in my batch job:
 
public void execute(Database.BatchableContext BC, List<sObject> recs) {

        for (sObject sObj : recs) {
            Account acct = (Account)sObj;
            acct.Growth_Rate__c = 0;
        }
        
        try {
            // Update Accounts
            Database.SaveResult[] srList = Database.update(recs, false);            
            
            Set<Id> errorIds = new Set<Id>();
            for (Database.SaveResult sr : srList) {
                if (!sr.isSuccess()) {
                    errorIds.add(sr.getId());
                }
            }
            System.debug('errorIds: ' + errorIds);
        }
        catch (Exception ex) {
			System.debug('Exception thrown: ' + ex.getMessage());
        }
}

Any help would be greatly appreciated.

Thanks,
Al
I'm getting an error in the Developer Console when I attempt to open a file (File->Open menu).  The Open dialog appears and the error "Insufficient_Access Could not load Apex class from Salesforce: insufficient access rights on cross-reference id" appears.  If I click OK on the error message, it goes away.  I am able to select the other entity types in the Open dialog (Triggers, Pages, Page Components, etc) without error.

Any advice?

Developer Console Error Message
Hello,

I've created a batch job where I am updating some Account records.  In the job I am trying to run a Database.update call passing false as the 2nd parameter to enable saving of successful records even if some of them fail.  The problem I am having is that when 1 of the records fails due to a validation error, it is throwing an exception and not saving the rest of the records.  The documentation states this should not occur and that instead the records that didn't fail should be saved and the failed records be returned from the method call in a Database.SaveResult[] array.What is even stranger is that I have wrapped the Database.update call in a try..catch block and the exception isn't even caught.  I am thinking there is a bug somewhere in the platform causing this not to work as it previously used to.  Here is the code for the execute method in my batch job:
 
public void execute(Database.BatchableContext BC, List<sObject> recs) {

        for (sObject sObj : recs) {
            Account acct = (Account)sObj;
            acct.Growth_Rate__c = 0;
        }
        
        try {
            // Update Accounts
            Database.SaveResult[] srList = Database.update(recs, false);            
            
            Set<Id> errorIds = new Set<Id>();
            for (Database.SaveResult sr : srList) {
                if (!sr.isSuccess()) {
                    errorIds.add(sr.getId());
                }
            }
            System.debug('errorIds: ' + errorIds);
        }
        catch (Exception ex) {
			System.debug('Exception thrown: ' + ex.getMessage());
        }
}

Any help would be greatly appreciated.

Thanks,
Al
Hello,

We have an issue where a Set object contains duplicate elements,
but the elements contain the same hashCode. Isn't the hashCode the
determining factor when considering whether there are duplicate items
in a Set ?

The problem starts on line:
        o.Most_Recent_Lead__c = lead.Id;       (see below)

If I comment this line out , there is no issue.

We are then moving the Set object to a List object, expecting
it to have unique elements, then attempt to perform a Database.update.
When attempting this, we get
            Duplicate id in list: 0065B000002HyxqQAC
for ( Opportunity o : oppList ){
        if ( o.accountId != null ){
            Id contactId = someMap.get( o.AccountId );
            if ( contactId != null ){
                List<Leads__c> tmpLeads = someOtherMap.get( contactId );

                if ( tmpLeads != null ){
                    DateTime mostRecent;
                    Leads__c mostRecentLead;
                    for ( Leads__c lead : tmpLeads ){

                        lead.Opportunity__c = o.Id;                                                                                        
                        if ( mostRecent == null || lead.createdDate > mostRecent ){
                            mostRecent = lead.createdDate;
                            o.Most_Recent_Lead__c = lead.Id;
                        }

                        if(updateOppSet.contains(o)){
                            System.debug('Already contains opp'); 
                        } else {
                            updateOppSet.add( o );
                        }
                        System.debug('Hashcode: ' + updateOppSet.hashCode());     // Debugging purposes
                        for ( Opportunity o1 : updateOppSet){
                            System.debug('Hashcode for elm: ' + System.hashCode(o1));
                        }         
                    }   
                }
            }   
        }
    }
    List<Opportunity> updateOppList = new List<Opportunity>();
    updateOppList.addAll( updateOppSet );
    
    Database.Saveresult[] results = Database.update(updateOppList, false);

Wondering why this is happening and if anyone can offer suggestions.

Much appreciated
Chris
I am having issues to get the Classes loaded once Developer Console is launched. The Open window hangs on classes but as I scroll up and down thru other entities it loads those objects like Triggers, Pages etc. Anyone know the solution to this. I have changed browsers between Google and IE and still same behavior.
I am having issues to get the Classes loaded once Developer Console is launched. The Open window hangs on classes but as I scroll up and down thru other entities it loads those objects like Triggers, Pages etc. Anyone know the solution to this. I have changed browsers between Google and IE and still same behavior.