• Zuri Linn
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I have written the following test class and receive error "FATAL_ERROR System.DmlException: Insert failed. First exception on row 0 with id 0015B000015c9L1QAI; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]" when I run it, can anyone tell me what I am doing wrong?

@isTest
private class test_SaveAccountDetails {
    
    static testmethod void SaveAccountDetailTest() {
        Id RecordTypeIdPropAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
        
        Account acctForm = new Account();
        acctForm.RecordTypeId=RecordTypeIdPropAccount;
        acctForm.Name = 'Test Account';
        acctForm.PropertyNumber__c = '123456';
        acctForm.PropertyType__c = 'Retail';
        acctForm.Phone = '8885551212';
        acctForm.PropertyStatus__c = 'Potential Acquisition';
        acctForm.Website = 'www.testsite.com';
        acctForm.Description = 'test account description';
        acctForm.Region__c = 'test region';
        acctForm.PurchaseDate__c = date.parse('2/2/2000');
        acctForm.PurchasePrice__c = 350000;    
        acctForm.DateSold__c = date.parse('2/2/2019');
        acctForm.SalePrice__c = 500000;
        acctForm.BillingCountry = 'United States';   
        acctForm.ShippingCountry = 'United States';
        acctForm.BillingStreet = '1313 Mockingbird Lane';
        acctForm.ShippingStreet = '100 Art Rooney Ave';
        acctForm.BillingCity = 'Springfield';
        acctForm.BillingState = 'Missouri';    
        acctForm.ShippingCity = 'Pittsburgh';
        acctForm.ShippingState = 'Pennsylvania';
        acctForm.BillingPostalCode = '12345';   
        acctForm.ShippingPostalCode = '15212';
        
        insert acctForm;
        
        Test.startTest();        
        SaveAccountDetails.SaveAccountDetail(acctForm);
        Test.stopTest();
            
        
        
    }
}

Here is the class I am trying to provide code coverage for:

public class SaveAccountDetails {
    
    @AuraEnabled
    public static id SaveAccountDetail(Account acctForm){
        //DML operation to save AcctForm Details
        system.debug(acctForm);
        Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
        acctForm.RecordTypeId=recTypeId;
        insert acctForm;
        return acctForm.id;
    }
}

I would really appreciate any help provided!
Hello,

I am new to apex development and need some help with a Batch Apex job, I need to pull the ownerId from a custom object "Forecasting", find all accounts that have that ownerId listed as the account owner, then query all invoices for those accounts and sum the invoice amounts for each month of the year and put the total in a field on the Forecasting detail object, the Forecast detail records are each month of the year.  Busier months could involve hundreds of thousands of invoice records.  Can anyone help me in working through this without hitting any governor limits?
I have written the following test class and receive error "FATAL_ERROR System.DmlException: Insert failed. First exception on row 0 with id 0015B000015c9L1QAI; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]" when I run it, can anyone tell me what I am doing wrong?

@isTest
private class test_SaveAccountDetails {
    
    static testmethod void SaveAccountDetailTest() {
        Id RecordTypeIdPropAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
        
        Account acctForm = new Account();
        acctForm.RecordTypeId=RecordTypeIdPropAccount;
        acctForm.Name = 'Test Account';
        acctForm.PropertyNumber__c = '123456';
        acctForm.PropertyType__c = 'Retail';
        acctForm.Phone = '8885551212';
        acctForm.PropertyStatus__c = 'Potential Acquisition';
        acctForm.Website = 'www.testsite.com';
        acctForm.Description = 'test account description';
        acctForm.Region__c = 'test region';
        acctForm.PurchaseDate__c = date.parse('2/2/2000');
        acctForm.PurchasePrice__c = 350000;    
        acctForm.DateSold__c = date.parse('2/2/2019');
        acctForm.SalePrice__c = 500000;
        acctForm.BillingCountry = 'United States';   
        acctForm.ShippingCountry = 'United States';
        acctForm.BillingStreet = '1313 Mockingbird Lane';
        acctForm.ShippingStreet = '100 Art Rooney Ave';
        acctForm.BillingCity = 'Springfield';
        acctForm.BillingState = 'Missouri';    
        acctForm.ShippingCity = 'Pittsburgh';
        acctForm.ShippingState = 'Pennsylvania';
        acctForm.BillingPostalCode = '12345';   
        acctForm.ShippingPostalCode = '15212';
        
        insert acctForm;
        
        Test.startTest();        
        SaveAccountDetails.SaveAccountDetail(acctForm);
        Test.stopTest();
            
        
        
    }
}

Here is the class I am trying to provide code coverage for:

public class SaveAccountDetails {
    
    @AuraEnabled
    public static id SaveAccountDetail(Account acctForm){
        //DML operation to save AcctForm Details
        system.debug(acctForm);
        Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Property').getRecordTypeId();
        acctForm.RecordTypeId=recTypeId;
        insert acctForm;
        return acctForm.id;
    }
}

I would really appreciate any help provided!