axaykumar / force-dot-com-esapi

Automatically exported from code.google.com/p/force-dot-com-esapi
0 stars 0 forks source link

Inserting relationship #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I want to know if it is possible to insert object with relationship, because i 
don't think it is doing it. 
For my case, as we do not have full access to the inserted list of object, and 
that i need the inserted list to be able to insert its child or dependent list. 
So i opted to do it via relationship like this : 

t.Notes__c = j.Notes__c 
t.Description__c = j.Description__c
Customer_Information__c ci = new Customer_Information__c(TECH_External_ID__c = 
j.id + uniqueKey);
t.Customer_Information__r = ci;

but then, i can't specify the relationship in the field list, because its not a 
field, and if i do not specify it, then the relationship is not created. Hoe to 
catter for this?

Original issue reported on code.google.com by vanessen...@sc-mauritius.com on 11 Mar 2014 at 9:58

GoogleCodeExporter commented 8 years ago
The ESAPI Library currently doesn't support inserting related objects. My 
recommendation for this scenario will be to validate access permission by using 
the isAuthorizedTo* methods before doing a regular DML operation.

For example:

boolean obj1 = 
ESAPI.accessController().isAuthorizedToCreate(Obj1__c.getSObjectType(), new 
List<String>{'field1__c','field2__c'});

boolean obj2 = 
ESAPI.accessController().isAuthorizedToCreate(Obj2__c.getSObjectType(), new 
List<String>{'field1__c','obj1__c'}); //Notice the lookup object to obj1 here

if (obj1 && obj2){

obj1 o1 = new obj1(....);
obj2 o2 = new obj2();
o2.obj1__r = o1;

insert o1;
insert o2;

}else{
//handle error here
}

Original comment by jonathan...@gmail.com on 5 May 2014 at 4:22