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
MotokiMotoki 

JSP Partner Upsert Statement.

Hi guys,
 
I'm wondering if there is any example of how to write a upsert statment to update some data in a JSP page? I was trying to copy the way how the Partner Java sample would handle the upsert statement but couldn't get it right on jsp... This is my first time trying to do salesforce on jsp, so if anyone could help would be great.
 
Thanks alot!
Richie
 
 
MotokiMotoki
Code:
SObject[] updates = new SObject[payment_update_list.size()];
     
for(int i=0; i < payment_update_list.size(); i++)
{
 HashMap item = (HashMap) payment_update_list.get(i);
 String id = item.get("Id").toString();
 String status = item.get("status").toString();
        MessageElement[] mfields = new MessageElement[2];
      
        MessageElement m_id = new MessageElement("", "Id");
 m_id.setObjectValue(id);
 Element e = m_id.getAsDOM();
 e.removeAttribute("xsi:type");
 e.removeAttribute("xmlns:ns1");
 e.removeAttribute("xmlns:xsd");
 e.removeAttribute("xmlns:xsi");
 m_id = new MessageElement(e);

        MessageElement m_Status = new MessageElement("", "Status_ID__c");
 m_Status.setObjectValue(status);
 Element e2= m_Status.getAsDOM();
 e2.removeAttribute("xsi:type");
 e2.removeAttribute("xmlns:ns1");
 e2.removeAttribute("xmlns:xsd");
 e2.removeAttribute("xmlns:xsi");
 m_Status = new MessageElement(e2);
    
        mfields[0] = m_id; 
 mfields[1] = m_Status; 

        updates[i] = new SObject();
 updates[i].set_any(mfields);
 updates[i].setType("Purchase_Record__c");
}

UpsertResult[] results1 = binding.upsert("Id", updates);
for (int k=0; k < results1.length; k++)
{
 response.getWriter().print("Item: " + new Integer(k).toString()+ "<br/>");
        if (results1[k].isSuccess())
        {
        response.getWriter().print("InReview record updated with an id: " +
  results1[k].getId()+ "<br/>");
        } else {
        response.getWriter().print("Item " + new Integer(k).toString() +
                " had an error updating." + "<br/>");

          response.getWriter().print("The error resported was: " +
                results1[k].getErrors()[0].getMessage() + "<br/>");
  }
}

 
The above is the section i tried to upsert something in the jsp page but i keep getting the error said the "id" and "status" i put in "m_id.setObjectValue(id)"  and "m_Status.setObjectValue(status)" are null. I tried to print the variables on the screen and found out they are not null but when i tried to do m_Status.getObjectValue(status) and m_id.getObjectValue(id) then all i get is null...
 
Can anyone please tell me why? It works in Java but why not in jsp??
 
Thanks
Richie