camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Satguru Srivastava (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-10193) add support for lookup field using an sObject external id
Date Wed, 03 Aug 2016 21:02:20 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-10193?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15406601#comment-15406601
] 

Satguru Srivastava edited comment on CAMEL-10193 at 8/3/16 9:01 PM:
--------------------------------------------------------------------

[~dhirajsb]
It does require some work. 
We have done some work on this and can help out.

Now an sObject description does provide the name of the sObject a field might be referencing/looking
up but does not provide the sObject's external field name by which that field does the lookup.
Further a sObject can have multiple external ids and any one of them could be used for lookup.
So it makes sense to have the user provide this information.
Our implementation adds a new element called "sObjectExternalIdMap" under the salesforce maven
plugin "configuration" element.
This provides mapping of a sObject to its external id field.
Here is how it might look
{code:xml}
<configuration>
	<sObjectExternalIdMap>
		<Account>BranchCode__c</Account>
		<Case>ExtField__c</Case>
		...

	</sObjectExternalIdMap>
</configuration>
{code}
So here Account's external id is BranchCode_c, Cases's external id is ExtField__c and so on
During processing the plugin checks if a field is a lookup field and if yes then has the user
provided a mapping for the sObject being looked up.
If yes then it generates a Lookup class for that field and sets the type of the field to that
class.
If not then it sets the type to String (the default behavior as before).

So, for example, if Contact does a lookup on Account via field AccountName then in the Contact
DTO it sets AccountName field type to AccountLookup and also creates a class called AccountLookup
{code:java}
public class AccountLookup implements Lookup{

    private String BranchCode__c;

    public void setBranchCode__c(String e){
    	this.BranchCode__c = e;
    }
    
    public String getBranchCode__c(){
    	return this.BranchCode__c;
    }
    ...

}
{code}

Further if the lookup field is a custom field and thus ends with "__c" , the plugin replaces
"__c" with "__r"

So if Contact did a lookup on Account using a custom field called say "CustomField__c" then
in the Contact DTO it changes the name of the field to "CustomField__r" and of course sets
the type to AccountLookup.


On serialization these generate
{code:javascript}
{
	...
	
	AccountName : {
		BranchCode__c:"123"	
	},

	CustomField__r : {
		BranchCode__c:"456"	
	}
	...
}
{code}

We have been using this implementation for the last month or so and it seems to be working
ok.

This is also backward compatible, so if no "sObjectExternalIdMap"  is provided under "configuration"
element the plugin works exactly as before.

Let me create a pull request for you to review and see if it helps.



was (Author: ssatguru):
[~dhirajsb]
It does require some work. 
We have done some work on this and can help out.

Now an sObject description does provide the name of the sObject a field might be referencing/looking
up but does not provide the sObject's external field name by which that field does the lookup.
Further a sObject can have multiple external ids and any one of them could be used for lookup.
So it makes sense to have the user provide this information.
Our implementation adds a new element called "sObjectExternalIdMap" under the salesforce maven
plugin "configuration" element.
This provides mapping of a sObject to its external id field.
Here is how it might look
{code:xml}
<configuration>
	<sObjectExternalIdMap>
		<Account>BranchCode__c</Account>
		<Case>ExtField__c</Case>
		...

	</sObjectExternalIdMap>
</configuration>
{code:xml}
So here Account's external id is BranchCode_c, Cases's external id is ExtField__c and so on
During processing the plugin checks if a field is a lookup field and if yes then has the user
provided a mapping for the sObject being looked up.
If yes then it generates a Lookup class for that field and sets the type of the field to that
class.
If not then it sets the type to String (the default behavior as before).

So, for example, if Contact does a lookup on Account via field AccountName then in the Contact
DTO it sets AccountName field type to AccountLookup and also creates a class called AccountLookup
{code}
public class AccountLookup implements Lookup{

    private String BranchCode__c;

    public void setBranchCode__c(String e){
    	this.BranchCode__c = e;
    }
    
    public String getBranchCode__c(){
    	return this.BranchCode__c;
    }
    ...

}
{code}

Further if the lookup field is a custom field and thus ends with "__c" , the plugin replaces
"__c" with "__r"

So if Contact did a lookup on Account using a custom field called say "CustomField__c" then
in the Contact DTO it changes the name of the field to "CustomField__r" and of course sets
the type to AccountLookup.


On serialization these generate
{code}
{
	...
	
	AccountName : {
		BranchCode__c:"123"	
	},

	CustomField__r : {
		BranchCode__c:"456"	
	}
	...
}
{code}

We have been using this implementation for the last month or so and it seems to be working
ok.

This is also backward compatible, so if no "sObjectExternalIdMap"  is provided under "configuration"
element the plugin works exactly as before.

Let me create a pull request for you to review and see if it helps.


> add support for lookup field using an sObject external id
> ---------------------------------------------------------
>
>                 Key: CAMEL-10193
>                 URL: https://issues.apache.org/jira/browse/CAMEL-10193
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-salesforce
>    Affects Versions: 2.17.2
>            Reporter: Satguru Srivastava
>            Assignee: Dhiraj Bokde
>
> A SalesForce object can have a field of type called "lookup". 
> This field is used to by a record in a SalesForce object to reference a record in another
SalesForce object. 
> The value of this field could be a string in which case it would be the record id of
the other record or it could be an object in which case it would contain the other Object's
external field name and its value in that other record. 
> Doing lookup/reference by external id is very useful  specially for insert/upsert operations
as otherwise one has to maintain record id of each of the records in the other Object.
> Camel SalesForce component supports lookup by record id. 
> There is no support for the second type that is the external field name and value type.
>  
> See here for more information on this 
> https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm
>  Section "Upserting Records and Associating with an External ID" 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message