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
FredoDevFredoDev 

Update a LooK Up Type field

Hi  dev,

 

i have a scenario to update an lookup data type field using a string value . can anybody give me the idea / snippet. below i have pasted my code and also the error occur in the result of update function

 

Update = new Account[dtUpdate.Rows.Count];

UpdateItem.Id = Convert.ToString(dtUpdate.Rows[row]["Id"]);

UpdateItem.Tax_Schedule_Name__c = Convert.ToString(dtUpdate.Rows[row]["Tax_Schedule_Name__c"]);   LOOKUP FIELD

UpdateItem.Customer_ID__c = Convert.ToString(dtUpdate.Rows[row]["Customer_ID__c"]);

Update[row] = UpdateItem;

UpdateResult = SFService.update(Update);

 

Error Msg : The Update failed for above record because: Tax Schedule Name: id value of incorrect type: ABC SALES

 

"ABC SALES " IS THE VALUE I AM ASSIGNING TO IT AND ALSO THAT VALUE EXISTS IN THE TAX MASTER TABLE

Keyur PatelKeyur Patel

Hi,

 

I don't know, it would help you or not but please try with following code for update a look up field.

==========================================

public void updateForeignKeySample(String oppId)
{
   try { Opportunity updateOpportunity = new Opportunity();
      // Point to an existing opportunity to update
      updateOpportunity.Id = oppId;
      updateOpportunity.StageName = "Prospecting";

      Account parentAccountRef = new Account();
      parentAccountRef.MyExtId__c = "SAP1111111";
      updateOpportunity.Account = parentAccountRef;

      SaveResult[] results = binding.update(
         new sObject[] { updateOpportunity });
   }
   catch (SoapException e)
   {
      Console.WriteLine("An unexpected error has occurred: " +
                                 e.Message + "\n" + e.StackTrace);
   }
}

===========================================

Please refer following link for more details.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update.htm

 

Regards,

Keyur Patel