You need to sign in to do that
Don't have an account?
Can Java code upate a lookup field
Hello,
I would like to know if a WS client using API can update a lookup field in a custom object. So far I've searched the forum for a solution since I've been fighting with it for a while. I try to lookup Contacts from a Account object and assign it to a custom object that has a lookup field Contact__c if its already null,
This is the sequence I am doing,
1. I check if Contact__c is null in the object custom__c
2. if null, I query the parent object Account for the Contacts
3. I get the Contacts in the Account and try to set the custom__c's lookup field as
- custom__cObj.setId(id)
- custom__cObj.Contact__r((Contact) qr.getRecords[i])
- binding.update(new SObject[] {custom__cObj})
where qr.getRecords[i] is a Contact.
Most people in the board talk about a trigger populating a lookup field, I am just wondering what I am doing wrong here. My code does not error out, this makes the situation worser. I am just not able to update the lookup Contact field. Could anyone please help me out on this. Thanks a lot.
Hi, some thoughts:
1. put your code in a try / catch block and see if you're throwing any exceptions.
2. capture the return value from binging.update() and see if you got success, or some error.
3. I've not tried assigning a lookup via the _r variable. I'd try:
custom_cObj.Contact__c = qr.getRecords[i].id; // Set the ID value for the lookup directly.
Best, Steve.