function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
visualforce_devvisualforce_dev 

creation of validation rule using java

Hi,
i have created a custom object and custom fields using java code and metadata API. I want to create a validation rule for a field in this object. I used the following code
Code:
    ValidationRule vr[];
    vr = new ValidationRule [1];
    ValidationRule vrule = new ValidationRule();
    vrule.setFullName(co.getFullName()+".myvalidation__c");
    vrule.setErrorConditionFormula("Name='sumi'");
    vrule.setErrorMessage("Validationisworking");
    vrule.setDescription("Myvalidationruledesc");
    vr[0]=vrule;
    co.setValidationRules(vr);
    try
    {
    UpdateMetadata updateMetadata = new UpdateMetadata();
    co.setNameField(namefield);
    updateMetadata.setMetadata(co);
    updateMetadata.setCurrentName(objectname.toString());
    
    AsyncResult[] ars1 = msfdc.update(new UpdateMetadata[]{updateMetadata});
    if(ars1.length>0)
    {
     System.out.println("Updated Successfully");
     
    }
    }
    catch(Exception e)
    {
     System.out.println("Exception:" +e);
    }
    

 

 
where 'co' is the custom object. But following error is coming

Cannot create child objects through metadata create / update. The ValidationRule must named 'obj13__c.myvalidation__c' be created separately

 

 

Any help will be grt...

Thanks in advance.


Message Edited by visualforce_dev on 01-11-2009 07:52 PM
Message Edited by visualforce_dev on 01-22-2009 03:36 AM
Message Edited by visualforce_dev on 01-22-2009 03:40 AM
visualforce_devvisualforce_dev

its working now, dont give __c while setting name. closing this thread. :smileyvery-happy: