cjariscdk | Posts: 15

Salesforce Test Class Error

0 votes

We are working on creating Onespan transactions in Salesforce and have written out some Apex Trigger code to assist with the process. In order to use it in Production, we will need to write an apex test class that cover the code itself. In doing this, we are facing the below error when we try to insert, in Salesforce, a Onespan Transaction record. We are able to do the API callouts properly and they do get created on the OneSpan side. Has anyone received this error before or know what we need to do to not run into it?

Error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You need to open the record before you can edit it.


talk2bks | Posts: 34

Reply to: Salesforce Test Class Error

0 votes

This appears to be a validation rule on the object. Check your validation rules with that error "You need to open the record before you can edit it."


Duo_Liang | Posts: 3776

Reply to: Salesforce Test Class Error

0 votes

Hi Charles and Shrishti,

 

Happy new year and thanks for reaching out to us! This error message comes from the label "Inline_edit_error" which still sounds like there are code where creates objects inline:

    <labels>
        <fullName>Inline_edit_error</fullName>
        <categories>Error Message</categories>
        <language>en_US</language>
        <protected>false</protected>
        <shortDescription>Inline edit error</shortDescription>
        <value>You need to open the record before you can edit it.</value>
    </labels>

Could you double check your test code and avoid initiating objects like this:

FeedItem objPost=new FeedItem(
    IsRichText=true,
    ParentId = '0012v00003JMBTqAAP',
    Body = 'Hello there from <b>SalesforceCodex.com</b>'
);
insert objPost;

Instead, to create objects in this fashion:

AddressService addService=new addService();
zip.ZipCode='10011';
zip.Address1='47 W 13th St';
zip.Address2='';
zip.State='NY';
 

 

Duo

 

 


shrishti.jain@… | Posts: 2

Reply to: Salesforce Test Class Error

0 votes

Hi Duo,

This is the code for a test class, we are simply trying to create a transaction record and we are again getting the error " Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You need to open the record before you can edit it." on the "insert testPackage".

        Test.startTest();
        Deal_State__c testDealState = new Deal_State__c();
        testDealState.Docusign_Envelope_Status__c = 'Sent';
        insert testDealState;
        
        ESL__Package__c testPackage = new ESL__Package__c();
        testPackage.Name = 'Test Package';
        testPackage.Deal_State__c = testDealState.Id;
        testPackage.ESL__Status__c = 'Sent';
        insert testPackage;
        Test.stopTest();


Bert | Posts: 1

Reply to: Salesforce Test Class Error

0 votes

Hi Duo, Shrishi, Charles,

Just want to quickly pitch in: i'm having the same issue. I've essentially limited the test-code to:

        ESL__Package__c TestPackage = new ESL__Package__c();
        //TestPackage.ESL__Status__c = 'Draft';
        //TestPackage.ESL__Opportunity__c = TestOpportunity.id;
        //TestPackage.ESL__Silanis_Package_Id__c = 'Test_ID_For_APEX_Unit_Test';
        insert TestPackage;

I've tried above both with the fields added 'in line', on loose lines, and (as displayed above) even commented them out. Sadly without luck, the error persists.

The Debug log seems to indidate that, once I insert the ESL__Package__c object the Managed Package starts doing 'things'. The last 'thing' it does is described/logged as "13:19:07.757 (3207700530)|DML_BEGIN|[734]|Op:Insert|Type:ESL__ReminderConfiguration__c|Rows:1", after that it crashes. I've attached the log to this post.

Can you advise?


Attachments
Duo_Liang | Posts: 3776

Reply to: Salesforce Test Class Error

0 votes

Hi Bert and Shrishi,

 

Thanks for the information!

I can reproduce the same error if I used similar code in a test function and inserted ESL__Package__c. After some investigation, this is caused by trigger Package_RestrictInline. I attempted several options to bypass the restriction, and below two highlighted lines seems could do the trick if I added them before the insertion:


@IsTest
public class DuoTest20240115_Test {
    static testMethod void doAllTest(){
        PageReference pageRef = new PageReference('/apex/esl__test');
        Test.setCurrentPage(pageRef);


        ESL__Package__c TestPackage = new ESL__Package__c();
         ......
        insert TestPackage;       
    }       

Let me know if adding these two lines work for you.

PS: Seems this error only happenes when insert from test case, if I invoked the same code from developer console, no error received. I can also insert an ESL__Package__c  record via SOAP API without receiving an error.

 

Duo


shrishti.jain@… | Posts: 2

Reply to: Salesforce Test Class Error

0 votes

Hi Duo

Thank you for the response the trick solved the insert issue.
Also, for an apex code test class which delete the package from the onespan but keep its salesforce record and then changes the status of the transaction in salesforce, I am getting a script exception as below. Can you please help me with this ?

EXCEPTION_THROWN [36]|System.DmlException: Update failed. First exception on row 0 with id aBeDE000000qt8d0AA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ESL.PackageTrigger: execution of BeforeUpdate


Duo_Liang | Posts: 3776

Reply to: Salesforce Test Class Error

0 votes

Hi Shrishi,

 

I am afraid this error is not able to be worked around. This error is caused because of the missing configuration object. 

To elaborate the nature of the issue, because salesforce test case has isolated data access from org data (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_access.htm), this makes some managed package classes not able to be initiated in test cases, and in particular for e_SignLive_Configuration__c which is a managed object stores the account preference settings.

 

Duo


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off