Skip to main content
[Edit removed during grace period]
Source Link
lhh13
  • 51
  • 1
  • 6
edited title
Link
lhh13
  • 51
  • 1
  • 6

I can't see or find in salesforce, or using query editor in the developer console, custom objectsobject records that have been created in apex

added 97 characters in body
Source Link
lhh13
  • 51
  • 1
  • 6

I'm running apex code that creates related records for a custom object when a record is created or updated. The code runs without errors however I cannot see any of the related records in Salesforce and using the query editor in the developer console on those related objects returns 0 results.

All related records are for custom objects. I don't see any error messages nor are any of my exception handlers being triggered. If I run the below code around my insert statement:

SObjectAccessDecision securityDecision = Security.stripInaccessible(AccessType.CREATABLE, financials); insert as user securityDecision.getRecords(); List<customnp__Financial_Detail__c> fds = [SELECT Name, CreatedById, Id FROM customnp__Financial_Detail__c]; System.debug('fds size: ' + fds.size()); 

It returns the number of records inserted, e.g. 6, and the Ids and CreatedByIds all show as expected.

I've checked that the required field for each inserted record are correct using this method as well.

There are around 10 related objects, each can have any number of records created for them (although realistically they'll only be 10 at most) but I have only checked one object's results are correct using debugging, but none are giving errors or throwing exceptions.

Running a basic example in execute annonymous does work when I use the above code at insert and I can see the results of that in Salesforce and using the query editor.

What might be causing this behaviour? I've checked the CreatedById matches my own user Id and as system admin permissions are complete for all objects.

To add to my confusion, for every record created of one custom object, i also create a contact record. I do this by querying the custom object using soql, and then for each result creating a list of new contacts and inserting it, this works fine but the object the contacts are based off shows no results.

I can add more code if needed but there's a lot, generally the objects are created in the simple pattern of new empty object, assign variables, add it to a list then insert list as above.

Thanks in advance for any ideas on what might be going wrong/what I'm missing.

Edit: in case this is relevant, I'm creating a package using 2GP and this is in a scratch org

I'm running apex code that creates related records for a custom object when a record is created or updated. The code runs without errors however I cannot see any of the related records in Salesforce and using the query editor in the developer console on those related objects returns 0 results.

All related records are for custom objects. I don't see any error messages nor are any of my exception handlers being triggered. If I run the below code around my insert statement:

SObjectAccessDecision securityDecision = Security.stripInaccessible(AccessType.CREATABLE, financials); insert as user securityDecision.getRecords(); List<customnp__Financial_Detail__c> fds = [SELECT Name, CreatedById, Id FROM customnp__Financial_Detail__c]; System.debug('fds size: ' + fds.size()); 

It returns the number of records inserted, e.g. 6, and the Ids and CreatedByIds all show as expected.

I've checked that the required field for each inserted record are correct using this method as well.

There are around 10 related objects, each can have any number of records created for them (although realistically they'll only be 10 at most) but I have only checked one object's results are correct using debugging, but none are giving errors or throwing exceptions.

Running a basic example in execute annonymous does work when I use the above code at insert and I can see the results of that in Salesforce and using the query editor.

What might be causing this behaviour? I've checked the CreatedById matches my own user Id and as system admin permissions are complete for all objects.

To add to my confusion, for every record created of one custom object, i also create a contact record. I do this by querying the custom object using soql, and then for each result creating a list of new contacts and inserting it, this works fine but the object the contacts are based off shows no results.

I can add more code if needed but there's a lot, generally the objects are created in the simple pattern of new empty object, assign variables, add it to a list then insert list as above.

Thanks in advance for any ideas on what might be going wrong/what I'm missing.

I'm running apex code that creates related records for a custom object when a record is created or updated. The code runs without errors however I cannot see any of the related records in Salesforce and using the query editor in the developer console on those related objects returns 0 results.

All related records are for custom objects. I don't see any error messages nor are any of my exception handlers being triggered. If I run the below code around my insert statement:

SObjectAccessDecision securityDecision = Security.stripInaccessible(AccessType.CREATABLE, financials); insert as user securityDecision.getRecords(); List<customnp__Financial_Detail__c> fds = [SELECT Name, CreatedById, Id FROM customnp__Financial_Detail__c]; System.debug('fds size: ' + fds.size()); 

It returns the number of records inserted, e.g. 6, and the Ids and CreatedByIds all show as expected.

I've checked that the required field for each inserted record are correct using this method as well.

There are around 10 related objects, each can have any number of records created for them (although realistically they'll only be 10 at most) but I have only checked one object's results are correct using debugging, but none are giving errors or throwing exceptions.

Running a basic example in execute annonymous does work when I use the above code at insert and I can see the results of that in Salesforce and using the query editor.

What might be causing this behaviour? I've checked the CreatedById matches my own user Id and as system admin permissions are complete for all objects.

To add to my confusion, for every record created of one custom object, i also create a contact record. I do this by querying the custom object using soql, and then for each result creating a list of new contacts and inserting it, this works fine but the object the contacts are based off shows no results.

I can add more code if needed but there's a lot, generally the objects are created in the simple pattern of new empty object, assign variables, add it to a list then insert list as above.

Thanks in advance for any ideas on what might be going wrong/what I'm missing.

Edit: in case this is relevant, I'm creating a package using 2GP and this is in a scratch org

Source Link
lhh13
  • 51
  • 1
  • 6
Loading