-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
5Replies
Trouble locating Contact Object Service Reference in .NET
I am able to login to salesforce.com using .NET.
The problem is using any of the standard objects.
I am unable to contruct a Contact or Account object.
I am guessing I need to add the Service Reference?
Not sure how to do that, since I'm still new to .NET
for salesforce.com
Here is my code, sorry code insert does not work!!!:
static void Main(string[] args)
{
string userName = "username";
string password = "password";
string soql = "select LastName,FirstName,TaxID__c from Contact";
SforceService SfdcBinding = null;
LoginResult CurrentLoginResult = null;
SfdcBinding = new SforceService();
try
{
//login
CurrentLoginResult = SfdcBinding.login(userName, password);
//reset the SOAP endpoint.
SfdcBinding.Url = CurrentLoginResult.serverUrl;
//set the session id into the binding
SfdcBinding.SessionHeaderValue = new SessionHeader();
SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;
Console.WriteLine("{0}",CurrentLoginResult.sessionId);
QueryResult queryResult = null;
queryResult = SfdcBinding.query(soql);
if (queryResult.size > 0)
{
//put some code in here to handle the records being returned
int i = 0;
Console.WriteLine("Logged in user can see "
+ queryResult.size + " contact records.");
sObject obj = new sObject();
//Lead lead = (Lead)queryResult.records[i];
//string firstName = lead.FirstName;
//string lastName = lead.LastName;
//string businessPhone = lead.Phone;
}
else
{
//put some code in here to handle no records being returned
string message = "No records returned.";
}
Any ideas would be greatly appreciated!
- mc1392
- February 03, 2010
- Like
- 0
using java retrieve
Im not sure how to create the "Account" object in this sample code.
Java gives me an error on the instantiation on the object called "Account".
private void retrieveSample() { try { // Invoke the retrieve call and save results in an array of SObjects SObject[] sObjects = binding.retrieve("Id, AccountNumber, Name, Website", "Account", new ID[] {new ID("001x0000002kuk1AAA"), new ID("001x0000002khE0AAI")}); // Verify that some objects were returned. // Even though we began with valid object IDs, // someone else might have deleted them in the meantime. if (sObjects != null) { // Loop through the array and print out some properties for (int i=0;i<sObjects.length;i++) { // Cast the SObject into an Account object Account retrievedAccount = (Account)sObjects[i]; System.out.println("Account: " + retrievedAccount.getId()); System.out.println(" AccountNumber = " + retrievedAccount.getAccountNumber()); System.out.println(" Name = " + retrievedAccount.getName()); System.out.println(" Website = " + retrievedAccount.getWebsite()); } } } catch (Exception ex) { System.out.println("An unexpected error has occurred." + ex.getMessage()); } }
Do I need to import that object from a particular jar file?
Should I try making an SObject or a generic java Object?
- mc1392
- September 09, 2009
- Like
- 0
error when updating a custom object
I get this error when updating a custom object.
Error updating financial account: No . in address field
Any idea what this is?
- mc1392
- August 18, 2009
- Like
- 0
multithreaded java to salesforce
All,
is it possible to open a session to salesforce, set binding.maintainsession, then open several threads to load data?
Right now it looks as if I woul have to create different id's to load from different machines/fork the process.
Any ideas in if multithreading is available on sfdc?
- mc1392
- August 10, 2009
- Like
- 0
finding exact field causing problem when creating object in salesforce
All,
I am trying to pipoint the field that is causing my exception. I am creating a custom object.
The error message is vague.
here's the exception:
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.io.IOException: java.lang.NullPointerException faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}stackTrace:java.io.IOException: java.lang.NullPointerException at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.java:275) at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1504) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:734) at org.apache.axis.encoding.ser.ArraySerializer.serialize(ArraySerializer.java:414) at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1504) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:801) at org.apache.axis.message.RPCParam.serialize(RPCParam.java:208) at org.apache.axis.message.RPCElement.outputImpl(RPCElement.java:433) at org.apache.axis.message.MessageElement.output(MessageElement.java:1208) at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:139) at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478) at org.apache.axis.message.MessageElement.output(MessageElement.java:1208) at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:315) at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269) at org.apache.axis.SOAPPart.saveChanges(SOAPPart.java:530) at org.apache.axis.SOAPPart.getContentLength(SOAPPart.java:229) at org.apache.axis.Message.getContentLength(Message.java:510) at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:371) at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) at org.apache.axis.client.Call.invokeEngine(Call.java:2784) at org.apache.axis.client.Call.invoke(Call.java:2767) at org.apache.axis.client.Call.invoke(Call.java:2443) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at com.sforce.soap.partner.SoapBindingStub.create(SoapBindingStub.java:2075) at mybeans.AccountLoader6.createFinancialAccounts(AccountLoader6.java:2611) at mybeans.AccountLoader6.uploadFinancialAccounts(AccountLoader6.java:641) at mybeans.AccountLoader6.main(AccountLoader6.java:179)
Here's the code:
private static List<String> createFinancialAccounts( List<FinancialAccount> account, SoapBindingStub binding, CryptWorker cryptWorker, List<String> contactIDs) throws UnsupportedEncodingException { System.out.println("create " + account.size() + " FinancialAccounts"); System.out.println("Creating FAs"); List<String> FAIDs = new ArrayList<String>(); LinkedList<SObject> updateList = new LinkedList<SObject>(); int counter1 = 0; for (Iterator<FinancialAccount> it = account.iterator(); it.hasNext();) { FinancialAccount fas = it.next(); MessageElement[] contact = null; if (fas.getBirthday() != null) { contact = new MessageElement[31]; contact[30] = new MessageElement(new QName("FABirthday__c"), fas.getBirthday()); } else { contact = new MessageElement[30]; } String decryptedTaxID = cryptWorker.decrypt(fas.getId().getTaxid()); contact[0] = new MessageElement(new QName("AccountOwner__c"), fas .getContactid()); if (fas.getState() != null && fas.getState() != "") { contact[1] = new MessageElement(new QName("FAState__c"), fas .getState()); } else { contact[1] = new MessageElement(new QName("FAState__c"), ""); } if (fas.getZipcode() != null && fas.getZipcode() != "") { contact[2] = new MessageElement(new QName("FAZip__c"), fas .getZipcode()); } else { contact[2] = new MessageElement(new QName("FAZip__c"), ""); } if (fas.getNameline1() != null) { contact[3] = new MessageElement(new QName("NameLine1__c"), fas .getNameline1()); } else { contact[3] = new MessageElement(new QName("NameLine1__c"), ""); } if (fas.getNameline2() != null && fas.getNameline2() != "") { contact[4] = new MessageElement(new QName("NameLine2__c"), fas .getNameline2()); } else { contact[4] = new MessageElement(new QName("NameLine2__c"), ""); } if (fas.getNameline3() != null) { contact[5] = new MessageElement(new QName("NameLine3__c"), fas .getNameline3()); } else { contact[5] = new MessageElement(new QName("NameLine3__c"), ""); } if (fas.getNameline4() != null && fas.getNameline4() != "") { contact[6] = new MessageElement(new QName("NameLine4__c"), fas .getNameline4()); } else { contact[6] = new MessageElement(new QName("NameLine4__c"), ""); } if (fas.getNameline5() != null && fas.getNameline5() != "") { contact[7] = new MessageElement(new QName("NameLine5__c"), fas .getNameline5()); } else { contact[7] = new MessageElement(new QName("NameLine5__c"), ""); } if (fas.getNameline6() != null && fas.getNameline6() != "") { contact[8] = new MessageElement(new QName("NameLine6__c"), fas .getNameline6()); } else { contact[8] = new MessageElement(new QName("NameLine6__c"), ""); } if (fas.getRepid() != null && fas.getRepid() != "") { contact[9] = new MessageElement(new QName("RepID__c"), fas .getRepid()); } else { contact[9] = new MessageElement(new QName("RepID__c"), ""); } if (decryptedTaxID != null && decryptedTaxID != "") { contact[10] = new MessageElement(new QName("TaxID__c"), decryptedTaxID.trim()); } else { contact[10] = new MessageElement(new QName("TaxID__c"), ""); } if (fas.getInterestedparty() != null) { contact[11] = new MessageElement( new QName("InterestedParty__c"), fas .getInterestedparty()); } else { contact[11] = new MessageElement( new QName("InterestedParty__c"), 1); } contact[12] = new MessageElement(new QName("Name"), fas.getId() .getAccountnumber()); contact[13] = new MessageElement(new QName("AccountID__c"), fas .getId().getAccountnumber()); if (fas.getBackoffice() != null) { contact[14] = new MessageElement(new QName("BackOffice__c"), fas.getBackoffice()); } else { contact[14] = new MessageElement(new QName("BackOffice__c"), ""); } if (fas.getCurrentmv() != null) { contact[15] = new MessageElement( new QName("FACurrentMktVal__c"), fas.getCurrentmv()); } else { contact[15] = new MessageElement( new QName("FACurrentMktVal__c"), new BigDecimal("0.00")); } if (fas.getBalancesasof() != null) { contact[16] = new MessageElement(new QName("BalancesAsOf__c"), fas.getBalancesasof()); } else { contact[16] = new MessageElement(new QName("BalancesAsOf__c"), TradeHelper.asOfDate(dateString)); } contact[17] = new MessageElement(new QName("Update_Method__c"), "AUTO"); if (fas.getCity() != null) { contact[18] = new MessageElement(new QName("FACity__c"), fas .getCity()); } else { contact[18] = new MessageElement(new QName("FACity__c"), ""); } if (fas.getBusinessphone() != null) { contact[19] = new MessageElement(new QName("BusinessPhone__c"), fas.getBusinessphone()); } else { contact[19] = new MessageElement(new QName("BusinessPhone__c"), ""); } if (fas.getHomephone() != null) { contact[20] = new MessageElement(new QName("HomePhone__c"), fas .getHomephone()); } else { contact[20] = new MessageElement(new QName("HomePhone__c"), ""); } if (fas.getAccounttype() != null) { contact[21] = new MessageElement(new QName("AccountType__c"), fas.getAccounttype()); } else { contact[21] = new MessageElement(new QName("AccountType__c"), ""); } if (fas.getRetirementaccount() != null) { contact[22] = new MessageElement(new QName( "RetirementAccount__c"), fas.getRetirementaccount()); } else { contact[22] = new MessageElement(new QName( "RetirementAccount__c"), false); } if (fas.getAccountsource() != null) { contact[23] = new MessageElement(new QName("AccountSource__c"), fas.getAccountsource()); } else { contact[23] = new MessageElement(new QName("AccountSource__c"), ""); } contact[24] = new MessageElement( new QName("BalancesUpdateDate__c"), balancesupdatedate); if (fas.getNameaddressasof() != null) { contact[25] = new MessageElement( new QName("NameAddressAsOf__c"), fas .getNameaddressasof()); } else { contact[25] = new MessageElement( new QName("NameAddressAsOf__c"), TradeHelper .asOfDate(dateString)); } if (fas.getCurrentcash() != null) { contact[26] = new MessageElement(new QName("FACurrentCash__c"), fas.getCurrentcash()); } else { contact[26] = new MessageElement(new QName("FACurrentCash__c"), new BigDecimal("0.00")); } if (fas.getHouseholdid() != null) { contact[27] = new MessageElement(new QName("HouseHold__c"), fas .getHouseholdid()); } else { contact[27] = new MessageElement(new QName("HouseHold__c"), null); } if (fas.getMgmtstyle() != null) { contact[28] = new MessageElement(new QName("ProgramName__c"), fas .getMgmtstyle()); } else { contact[28] = new MessageElement(new QName("ProgramName__c"), null); } if (fas.getBackoffice()!= null) { contact[28] = new MessageElement(new QName("Custodian__c"), fas .getBackoffice()); } else { contact[28] = new MessageElement(new QName("Custodian__c"), null); } SObject cons = new SObject(); cons.setType("EAST_FinancialAccount__c"); cons.set_any(contact); updateList.add(cons); counter1++; for (int i = 0; i < contact.length; i++) { System.out.println(contact[i]); } } int part; int offset = 0; int count = updateList.size(); while (count > 0) { part = 0; while (part < UPSERT_BATCH_SIZE && count > 0) { part++; count--; } SObject[] UPDATES = new SObject[part]; for (int x = offset; x < part + offset; x++) { if (x < updateList.size()) { UPDATES[x - offset] = updateList.get(x); } else { break; } } if (UPDATES.length > 0) { // HERE we update all the balances try { SaveResult[] saveResults = binding.create(UPDATES); for (SaveResult result : saveResults) { if (result.isSuccess()) { FAIDs.add(result.getId()); System.out.println("Success!"); } else { System.err .println("Did not create Financial Account: " + result.getErrors(0) .getMessage()); System.err.println(result.getErrors()[0]); FAIDs.add(null); } } // loop through the results, checking for errors for (int j = 0; j < saveResults.length; j++) { if (saveResults[j].isSuccess()) { System.out .println("-------------------------------Result" + saveResults[j] + new Integer(j).toString() + ": A financial account with an id of: " + saveResults[j].getId() + " was created."); } else { System.err .println(": Error creating financial account: " + saveResults[j].getErrors()[0] .getMessage() + "\n"); } } } catch (Exception ex) { ex.printStackTrace(); } } offset += UPSERT_BATCH_SIZE; } System.out.println("FAIDS:" + FAIDs.size()); // return created; return FAIDs; }
- mc1392
- May 07, 2009
- Like
- 0
Query Contact with where clause
Im trying to query tax id's from salesforce using a LinkedList of Strings.
Im am not performing it properly in batch/bulk format, so I am going over
my allotted requests for the day.
Can any help me out with this query?
private static LinkedList<String> queryContacts(LinkedList<String> ssns,SoapBindingStub binding){ LinkedList<String> taxid = new LinkedList<String>(); QueryResult qr = null; int count = 0; for(Iterator<String> it = ssns.iterator();it.hasNext();){ String txid = it.next(); String query = "select TaxID__c from Contact where TaxID__c="; ////////////////////////////////////// try { query+="'"+txid+"'"; qr = binding.query(query); if (qr.getSize() != 0) { for(int i =0;i<qr.getSize();i++){ SObject account = qr.getRecords()[i]; System.out.println("Retrieved account AccountNumber__c: " +getFieldValue(account.get_any(), "TaxID__c")); count++; } } else { System.out.println("Hmm...\nDid not find the account, that's strange."); taxid.add(txid); } System.out.println(count); //System.out.println("\nQuery succesfully executed."); } catch (ApiFault af) { System.out .println("\nFailed to execute query succesfully, error message was: \n" + af.getExceptionMessage()); } catch (Exception ex) { System.out .println("\nFailed to execute query succesfully, error message was: \n" + ex.getMessage()); } //////////////////////////////////////////////// } return taxid; }
- mc1392
- November 21, 2008
- Like
- 0
using java retrieve
Im not sure how to create the "Account" object in this sample code.
Java gives me an error on the instantiation on the object called "Account".
private void retrieveSample() { try { // Invoke the retrieve call and save results in an array of SObjects SObject[] sObjects = binding.retrieve("Id, AccountNumber, Name, Website", "Account", new ID[] {new ID("001x0000002kuk1AAA"), new ID("001x0000002khE0AAI")}); // Verify that some objects were returned. // Even though we began with valid object IDs, // someone else might have deleted them in the meantime. if (sObjects != null) { // Loop through the array and print out some properties for (int i=0;i<sObjects.length;i++) { // Cast the SObject into an Account object Account retrievedAccount = (Account)sObjects[i]; System.out.println("Account: " + retrievedAccount.getId()); System.out.println(" AccountNumber = " + retrievedAccount.getAccountNumber()); System.out.println(" Name = " + retrievedAccount.getName()); System.out.println(" Website = " + retrievedAccount.getWebsite()); } } } catch (Exception ex) { System.out.println("An unexpected error has occurred." + ex.getMessage()); } }
Do I need to import that object from a particular jar file?
Should I try making an SObject or a generic java Object?
- mc1392
- September 09, 2009
- Like
- 0
finding exact field causing problem when creating object in salesforce
All,
I am trying to pipoint the field that is causing my exception. I am creating a custom object.
The error message is vague.
here's the exception:
AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.io.IOException: java.lang.NullPointerException faultActor: faultNode: faultDetail: {http://xml.apache.org/axis/}stackTrace:java.io.IOException: java.lang.NullPointerException at org.apache.axis.encoding.ser.BeanSerializer.serialize(BeanSerializer.java:275) at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1504) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:734) at org.apache.axis.encoding.ser.ArraySerializer.serialize(ArraySerializer.java:414) at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1504) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980) at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:801) at org.apache.axis.message.RPCParam.serialize(RPCParam.java:208) at org.apache.axis.message.RPCElement.outputImpl(RPCElement.java:433) at org.apache.axis.message.MessageElement.output(MessageElement.java:1208) at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:139) at org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478) at org.apache.axis.message.MessageElement.output(MessageElement.java:1208) at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:315) at org.apache.axis.SOAPPart.writeTo(SOAPPart.java:269) at org.apache.axis.SOAPPart.saveChanges(SOAPPart.java:530) at org.apache.axis.SOAPPart.getContentLength(SOAPPart.java:229) at org.apache.axis.Message.getContentLength(Message.java:510) at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:371) at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) at org.apache.axis.client.Call.invokeEngine(Call.java:2784) at org.apache.axis.client.Call.invoke(Call.java:2767) at org.apache.axis.client.Call.invoke(Call.java:2443) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at com.sforce.soap.partner.SoapBindingStub.create(SoapBindingStub.java:2075) at mybeans.AccountLoader6.createFinancialAccounts(AccountLoader6.java:2611) at mybeans.AccountLoader6.uploadFinancialAccounts(AccountLoader6.java:641) at mybeans.AccountLoader6.main(AccountLoader6.java:179)
Here's the code:
private static List<String> createFinancialAccounts( List<FinancialAccount> account, SoapBindingStub binding, CryptWorker cryptWorker, List<String> contactIDs) throws UnsupportedEncodingException { System.out.println("create " + account.size() + " FinancialAccounts"); System.out.println("Creating FAs"); List<String> FAIDs = new ArrayList<String>(); LinkedList<SObject> updateList = new LinkedList<SObject>(); int counter1 = 0; for (Iterator<FinancialAccount> it = account.iterator(); it.hasNext();) { FinancialAccount fas = it.next(); MessageElement[] contact = null; if (fas.getBirthday() != null) { contact = new MessageElement[31]; contact[30] = new MessageElement(new QName("FABirthday__c"), fas.getBirthday()); } else { contact = new MessageElement[30]; } String decryptedTaxID = cryptWorker.decrypt(fas.getId().getTaxid()); contact[0] = new MessageElement(new QName("AccountOwner__c"), fas .getContactid()); if (fas.getState() != null && fas.getState() != "") { contact[1] = new MessageElement(new QName("FAState__c"), fas .getState()); } else { contact[1] = new MessageElement(new QName("FAState__c"), ""); } if (fas.getZipcode() != null && fas.getZipcode() != "") { contact[2] = new MessageElement(new QName("FAZip__c"), fas .getZipcode()); } else { contact[2] = new MessageElement(new QName("FAZip__c"), ""); } if (fas.getNameline1() != null) { contact[3] = new MessageElement(new QName("NameLine1__c"), fas .getNameline1()); } else { contact[3] = new MessageElement(new QName("NameLine1__c"), ""); } if (fas.getNameline2() != null && fas.getNameline2() != "") { contact[4] = new MessageElement(new QName("NameLine2__c"), fas .getNameline2()); } else { contact[4] = new MessageElement(new QName("NameLine2__c"), ""); } if (fas.getNameline3() != null) { contact[5] = new MessageElement(new QName("NameLine3__c"), fas .getNameline3()); } else { contact[5] = new MessageElement(new QName("NameLine3__c"), ""); } if (fas.getNameline4() != null && fas.getNameline4() != "") { contact[6] = new MessageElement(new QName("NameLine4__c"), fas .getNameline4()); } else { contact[6] = new MessageElement(new QName("NameLine4__c"), ""); } if (fas.getNameline5() != null && fas.getNameline5() != "") { contact[7] = new MessageElement(new QName("NameLine5__c"), fas .getNameline5()); } else { contact[7] = new MessageElement(new QName("NameLine5__c"), ""); } if (fas.getNameline6() != null && fas.getNameline6() != "") { contact[8] = new MessageElement(new QName("NameLine6__c"), fas .getNameline6()); } else { contact[8] = new MessageElement(new QName("NameLine6__c"), ""); } if (fas.getRepid() != null && fas.getRepid() != "") { contact[9] = new MessageElement(new QName("RepID__c"), fas .getRepid()); } else { contact[9] = new MessageElement(new QName("RepID__c"), ""); } if (decryptedTaxID != null && decryptedTaxID != "") { contact[10] = new MessageElement(new QName("TaxID__c"), decryptedTaxID.trim()); } else { contact[10] = new MessageElement(new QName("TaxID__c"), ""); } if (fas.getInterestedparty() != null) { contact[11] = new MessageElement( new QName("InterestedParty__c"), fas .getInterestedparty()); } else { contact[11] = new MessageElement( new QName("InterestedParty__c"), 1); } contact[12] = new MessageElement(new QName("Name"), fas.getId() .getAccountnumber()); contact[13] = new MessageElement(new QName("AccountID__c"), fas .getId().getAccountnumber()); if (fas.getBackoffice() != null) { contact[14] = new MessageElement(new QName("BackOffice__c"), fas.getBackoffice()); } else { contact[14] = new MessageElement(new QName("BackOffice__c"), ""); } if (fas.getCurrentmv() != null) { contact[15] = new MessageElement( new QName("FACurrentMktVal__c"), fas.getCurrentmv()); } else { contact[15] = new MessageElement( new QName("FACurrentMktVal__c"), new BigDecimal("0.00")); } if (fas.getBalancesasof() != null) { contact[16] = new MessageElement(new QName("BalancesAsOf__c"), fas.getBalancesasof()); } else { contact[16] = new MessageElement(new QName("BalancesAsOf__c"), TradeHelper.asOfDate(dateString)); } contact[17] = new MessageElement(new QName("Update_Method__c"), "AUTO"); if (fas.getCity() != null) { contact[18] = new MessageElement(new QName("FACity__c"), fas .getCity()); } else { contact[18] = new MessageElement(new QName("FACity__c"), ""); } if (fas.getBusinessphone() != null) { contact[19] = new MessageElement(new QName("BusinessPhone__c"), fas.getBusinessphone()); } else { contact[19] = new MessageElement(new QName("BusinessPhone__c"), ""); } if (fas.getHomephone() != null) { contact[20] = new MessageElement(new QName("HomePhone__c"), fas .getHomephone()); } else { contact[20] = new MessageElement(new QName("HomePhone__c"), ""); } if (fas.getAccounttype() != null) { contact[21] = new MessageElement(new QName("AccountType__c"), fas.getAccounttype()); } else { contact[21] = new MessageElement(new QName("AccountType__c"), ""); } if (fas.getRetirementaccount() != null) { contact[22] = new MessageElement(new QName( "RetirementAccount__c"), fas.getRetirementaccount()); } else { contact[22] = new MessageElement(new QName( "RetirementAccount__c"), false); } if (fas.getAccountsource() != null) { contact[23] = new MessageElement(new QName("AccountSource__c"), fas.getAccountsource()); } else { contact[23] = new MessageElement(new QName("AccountSource__c"), ""); } contact[24] = new MessageElement( new QName("BalancesUpdateDate__c"), balancesupdatedate); if (fas.getNameaddressasof() != null) { contact[25] = new MessageElement( new QName("NameAddressAsOf__c"), fas .getNameaddressasof()); } else { contact[25] = new MessageElement( new QName("NameAddressAsOf__c"), TradeHelper .asOfDate(dateString)); } if (fas.getCurrentcash() != null) { contact[26] = new MessageElement(new QName("FACurrentCash__c"), fas.getCurrentcash()); } else { contact[26] = new MessageElement(new QName("FACurrentCash__c"), new BigDecimal("0.00")); } if (fas.getHouseholdid() != null) { contact[27] = new MessageElement(new QName("HouseHold__c"), fas .getHouseholdid()); } else { contact[27] = new MessageElement(new QName("HouseHold__c"), null); } if (fas.getMgmtstyle() != null) { contact[28] = new MessageElement(new QName("ProgramName__c"), fas .getMgmtstyle()); } else { contact[28] = new MessageElement(new QName("ProgramName__c"), null); } if (fas.getBackoffice()!= null) { contact[28] = new MessageElement(new QName("Custodian__c"), fas .getBackoffice()); } else { contact[28] = new MessageElement(new QName("Custodian__c"), null); } SObject cons = new SObject(); cons.setType("EAST_FinancialAccount__c"); cons.set_any(contact); updateList.add(cons); counter1++; for (int i = 0; i < contact.length; i++) { System.out.println(contact[i]); } } int part; int offset = 0; int count = updateList.size(); while (count > 0) { part = 0; while (part < UPSERT_BATCH_SIZE && count > 0) { part++; count--; } SObject[] UPDATES = new SObject[part]; for (int x = offset; x < part + offset; x++) { if (x < updateList.size()) { UPDATES[x - offset] = updateList.get(x); } else { break; } } if (UPDATES.length > 0) { // HERE we update all the balances try { SaveResult[] saveResults = binding.create(UPDATES); for (SaveResult result : saveResults) { if (result.isSuccess()) { FAIDs.add(result.getId()); System.out.println("Success!"); } else { System.err .println("Did not create Financial Account: " + result.getErrors(0) .getMessage()); System.err.println(result.getErrors()[0]); FAIDs.add(null); } } // loop through the results, checking for errors for (int j = 0; j < saveResults.length; j++) { if (saveResults[j].isSuccess()) { System.out .println("-------------------------------Result" + saveResults[j] + new Integer(j).toString() + ": A financial account with an id of: " + saveResults[j].getId() + " was created."); } else { System.err .println(": Error creating financial account: " + saveResults[j].getErrors()[0] .getMessage() + "\n"); } } } catch (Exception ex) { ex.printStackTrace(); } } offset += UPSERT_BATCH_SIZE; } System.out.println("FAIDS:" + FAIDs.size()); // return created; return FAIDs; }
- mc1392
- May 07, 2009
- Like
- 0
Query Contact with where clause
Im trying to query tax id's from salesforce using a LinkedList of Strings.
Im am not performing it properly in batch/bulk format, so I am going over
my allotted requests for the day.
Can any help me out with this query?
private static LinkedList<String> queryContacts(LinkedList<String> ssns,SoapBindingStub binding){ LinkedList<String> taxid = new LinkedList<String>(); QueryResult qr = null; int count = 0; for(Iterator<String> it = ssns.iterator();it.hasNext();){ String txid = it.next(); String query = "select TaxID__c from Contact where TaxID__c="; ////////////////////////////////////// try { query+="'"+txid+"'"; qr = binding.query(query); if (qr.getSize() != 0) { for(int i =0;i<qr.getSize();i++){ SObject account = qr.getRecords()[i]; System.out.println("Retrieved account AccountNumber__c: " +getFieldValue(account.get_any(), "TaxID__c")); count++; } } else { System.out.println("Hmm...\nDid not find the account, that's strange."); taxid.add(txid); } System.out.println(count); //System.out.println("\nQuery succesfully executed."); } catch (ApiFault af) { System.out .println("\nFailed to execute query succesfully, error message was: \n" + af.getExceptionMessage()); } catch (Exception ex) { System.out .println("\nFailed to execute query succesfully, error message was: \n" + ex.getMessage()); } //////////////////////////////////////////////// } return taxid; }
- mc1392
- November 21, 2008
- Like
- 0