1

I am inserting an object in Apex which has two master-detail relationships to other objects but as far as I can tell, the permissions on these objects are set fine.

When I try to insert my records like so:

try
{
    insert sqrList;
}
catch(exception e)
{
    return 'false - inserting failed : ' + e.getMessage( );
}
return 'true';

What is returned is

'false - inserting failed : INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []'

However, I wanted to debug the exact message, therefore I did the following:

try
{
    insert sqrList;
}
catch (DmlException de) 
{
    Integer numErrors = de.getNumDml();
    string dmlExcep  = 'getNumDml : ' + numErrors;
    for( Integer j = 0; j < numErrors; j ++ ) 
    {
        dmlExcep += 'getDmlFieldNames=' + de.getDmlFieldNames(i);
        dmlExcep += 'getDmlMessage=' + de.getDmlMessage(i); 
    }
    dmlExcep += de.getMessage( ) + ' LINE_NUMBER : ' + de.getLineNumber( ) + 'STACKTRACE : ' + de.getStacktraceString( ) + ' try to insert : ' + sqrList;
    return dmlExcep;
}
catch(exception e)
{
    return e.getMessage( ) + ' LINE_NUMBER : ' + e.getLineNumber( ) + 'STACKTRACE : ' + e.getStacktraceString( ) + ' try to insert : ' + sqrList;
}
return 'true';

and now, this piece of code returns 'true' and the records are inserted. Can anyone explain this to me?

  • 1
    In general, you should always know what type of exception you are trying to catch and avoid catching untyped exceptions except as a last resort. – Adrian Larson Sep 1 '15 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.