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
saariko.ax241saariko.ax241 

Advanced: updating a class member with out knowing it's name

I have an xml I get from an external program. this XML holds information about multiple, unknown fields and their values.  the fields are a subset of a custom object in SF.
My question:
How can I set the value I get from the XML in the SF object? 
Limitations:
I dont' want to use a long if else/switch list
I don't want to update the code when in the future I add new fields to the SF object (the XML program will know of the new fields - and update them if needed)
 
XML example:
*The attribute : SF_Module_Name - holds the name of the SF Object member I want to set to true.
Code:
<—xml version="1.0" encoding="iso-8859-1"–>
<sale>
  <trxdata>
    <action>new</action>
  </trxdata>
  <Plugs>
    <Plug>
      <Dongle_ID__c>1576718528</Dongle_ID__c>
      <License_Expiration_Date>
      </License_Expiration_Date>
    </Plug>
  </Plugs>
  <Modules>
    <Module>
      <Dongle_ID__c></Dongle_ID__c>
      <Id>
      </Id>
      <Module_Name>OptiMark</Module_Name>
      <Module_Version>900</Module_Version>
      <SF_Module_Name>X1</SF_Module_Name>
    </Module>
    <Module>
      <Dongle_ID__c></Dongle_ID__c>
      <Id>
      </Id>
      <Module_Name>Optikk</Module_Name>
      <Module_Version>900</Module_Version>
      <SF_Module_Name>X2</SF_Module_Name>
    </Module>
    <Module>
      <Dongle_ID__c></Dongle_ID__c>
      <Id>
      </Id>
      <Module_Name>Opti33</Module_Name>
      <Module_Version>900</Module_Version>
      <SF_Module_Name>X3</SF_Module_Name>
    </Module>
  </Modules>
</sale>

 
I couldn't really figure how to use reflection on my object, since I couldnt' see how it is hashable, nor is it a mapped table.
 
Does anyone have an idea?
 
 
 
 
SuperfellSuperfell
Look at the partner WSDL, it makes these metadata driven style approachs easy.
saariko.ax241saariko.ax241

Thanks Simon, indeed, the partner WSDL was what I was looking for.

just for reference, my code now looks like this:

 

Code:

            foreach (XmlNode info in n_plug.ChildNodes)
            {
                if (info.InnerXml.Length > 0)
                {
                    l_licenseInfo[l_licenseInfoIndex] = l_doc.CreateElement(info.Name);
                    l_licenseInfo[l_licenseInfoIndex].InnerText = info.InnerXml;

                    switch (info.Name)
                    {
                        case "License_Expiration_Date__c":
                            DateTime l_dt = new DateTime((System.DateTime.Today.AddYears(1).Ticks));
                            l_licenseInfo[l_licenseInfoIndex].InnerText = l_dt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
                            break;
                        case "Account__c":
                            l_licenseInfo[l_licenseInfoIndex].InnerText = l_trxData.m_accountId;
                            break;
                        case "Account_Name__c":
                            // we need to ignore the Account name
                            l_licenseInfoIndex--;
                            break;
                    }

                    l_licenseInfoIndex++;
                }
            }


 

Thomas Shelby 26Thomas Shelby 26
You receive real-time results and may analyse your revenue by author, category, tag, and article. optidigital.ca/