1

I am facing the issue where I am unable to create a new Account object via apex.

However, I can create an account manually. I was wondering if it is related to permissions then I shouldn't be able to create an account manually as well, right?

I call create_contact from VF page, where I provide a number in parameter callfrom.

newRecord is set in the constructor via custom setting.

public PageReference create_contact() {
    
    String callfrom = System.currentPageReference().getParameters().get('callfrom');
    callfrom = String.escapeSingleQuotes(callfrom);
    
    if(newRecord == 'Account')
    {
        Account newAcc = new Account(Name = 'Anonymous', phone = callfrom);  
        if(Schema.sObjectType.Account.fields.Name.isCreateable() && Schema.sObjectType.Account.fields.phone.isCreateable() )
        {
            try{
                insert newAcc;
            }
            catch(DmlException e) 
            {
                System.debug('The following exception has occurred: ' + e.getMessage());
            }
        }
    }
}

Can you please clarify that if the permissions are separate for creating an account object manually vs creating an account object via apex?

2
  • 4
    Please edit your question to include the full error message that you're getting. You should probably get rid of your try/catch as well. It does little aside from swallow your error, and it makes it harder for you to get at the actual error message (and stack trace).
    – Derek F
    Oct 20 at 14:04
  • The problem is that the org where the issue is happening, I don't have access to developer console or debug logs. Therefore, I couldn't paste the error from the logs. Can you please clarify that if the permissions are separate for creating an account object manually vs creating an account object via apex?
    – Badar
    Oct 21 at 5:44

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.