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
lodoss1118lodoss1118 

Help on updating metadata components using crud

Hi i am making an application that will update the description/inline help text (Custom Field) from a CSV file.

 

Now i have done this in c# and got the basics worked out, the problem i am hitting is that when i convert the csv record into a Custom Field for update, i have to keep setting the type, which is of type enum FieldType and these values differ from describe fieldtypes and so creating a mapping table is out of the question.

 

Here is some code:

 

static void Main(string[] args)
        {
            SFDC_Enterprise.SforceService sv = new SFDC_Enterprise.SforceService();
            SFDC_Enterprise.LoginResult lr = sv.login("aaaa", "aaaaaaaaaaaaa");

            // set up a MetdataService client
            SFDC_Metadata.MetadataService ms = new SFDC_Metadata.MetadataService();
            ms.SessionHeaderValue = new SFDC_Metadata.SessionHeader();
            ms.SessionHeaderValue.sessionId = lr.sessionId;
            ms.Url = lr.metadataServerUrl; 

            Console.WriteLine("Logged in as {0}", lr.userInfo.userName); 

            FileHelperEngine engine = new FileHelperEngine(typeof(InlineHelpCSV));
            InlineHelpCSV[] helps = engine.ReadFile("InlineHelp.csv") as InlineHelpCSV[];
            List<SFDC_Metadata.CustomField> cfs = new List<SFDC_Metadata.CustomField>();

            /*SFDC_Metadata.CustomField cf = new SFDC_Metadata.CustomField();
            cf.fullName = "Service__c.Billing_End__c";
            cf.label = "Billing End";
            cf.type = SFDC_Metadata.FieldType.Date;
            cf.inlineHelpText = "Updated from WEB APP";

            SFDC_Metadata.UpdateMetadata mu = new SFDC_Metadata.UpdateMetadata();
            mu.metadata = cf; 
            mu.currentName = "Service__c.Billing_End__c";

            SFDC_Metadata.AsyncResult r = ms.update(new SFDC_Metadata.UpdateMetadata[] { mu })[0];
            int waitTimeMilliSecs = 1000;
          
            while (!r.done){
                System.Threading.Thread.Sleep(waitTimeMilliSecs);
                waitTimeMilliSecs *= 2;
                r = ms.checkStatus(new string[] { r.id })[0];
                Console.WriteLine("Status: {0}", r.state);
            }
            if (r.state == SFDC_Metadata.AsyncRequestState.Error){
                Console.WriteLine("Error : {0} {1}", r.statusCode, r.message);
            }else{
                Console.WriteLine("Done, updated inlinehelptext");
            }*/
            
            Console.WriteLine("Inlinetext updates found {0}", helps.Length);
            foreach (InlineHelpCSV a in helps)
            {
                Console.WriteLine(a.fullName + " - " + a.label + " - " + " - " + a.type + " - " + a.inlineHelpText);
                SFDC_Metadata.CustomField cf = new SFDC_Metadata.CustomField();
                cf.fullName = a.fullName;
                cf.label = a.label;
                //cf.type = 
                cf.inlineHelpText = a.inlineHelpText;
                cfs.Add(cf);
            }

            Console.ReadLine();
        }

 

So how i am supposed to dynamically get the metadata fieldtype enum?