0

I want to create a visualforce page by using Tooling api and I am doing this like below :

@RemoteAction
    public static String createInlinePage(String objectName) {
        objectName = String.escapeSingleQuotes(objectName.trim());
        System.debug(objectName+'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~objectName');
        String salesforceHost = GetBaseUrlForInstance;
        System.debug(GetBaseUrlForInstance);
        String urlmy =  salesforceHost+'/services/data/v29.0/sobjects/ApexPage';
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(urlmy);
        req.setHeader('Content-type', 'application/json');
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
        req.setBody('{"Name" : "'+objectName+'InlineAttachmentPage","Markup" : "<apex:page standardController=\''+objectName+'\' standardstylesheets=\'false\' cache=\'false\'><c:AttachPathInlineComponent objectId=\'{!$CurrentPage.parameters.id}\'/></apex:page>","ControllerType" : "1","MasterLabel":"'+objectName+'InlineAttachmentPage","ApiVersion":"29.0"}');
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug(res.getBody());
        return res.getBody();
    }

This code is working fine for standard Object but not working for custom Object.

When I tried this for custom Object I got this error

{"message":"The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.: Name","errorCode":"FIELD_INTEGRITY_EXCEPTION","fields":["Name"]}

Please guide me where I am wrong .

2
  • What name are you passing in? Commented Oct 8, 2014 at 13:37
  • Attachment_configuration__c
    – Eric
    Commented Oct 8, 2014 at 14:13

1 Answer 1

2

based on your comment, it is clear from the error string what the problem is -- you cannot pass in the name that you are. the error says you cannot have consecutive _ and using the API name for a custom object contains exactly that. you can test this by hand by attempting to set the name of a new visualforce page to something like TEST_NEWPAGE__C_DOUBLEUNDERSCORE. this will fail on save with the same error. in order to create a new visualforce page you will have to either strip out/replace double underscores or pass in the display name of the object.

2
  • I can create the page from ui or from Eclipse with same name. And if I will truncate anything from the name it will show "Object not found" error.
    – Eric
    Commented Oct 8, 2014 at 14:44
  • 1
    only the name of your page cannot have double underscores. all other references to the object should be fine. Commented Oct 8, 2014 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .