You need to sign in to do that
Don't have an account?
sabelstrom
Possible to create SELECT with variable fields
Given that queries in Apex code are performed differently, is it possible to make the fields requested from an object variable? As the documentation implies, a "bind" expression cannot be used. If this is not possible by some other approach, it would be a valuable enhancement/improvement.
Also, is there a way to investigate the fields on an object (akin to a DescribeSObject) when a trigger fires? Ideally something like a .js 'for ... in ... ' loop:
for(thisField in thisAccount){//do something w/ thisField.name}
Thanks!
Ron,
I've voted for this on the idea exchange. I'm using SF Apex in order to create "Deep Clone Opportunity" functionality, which not only clones the opportunity, but it also carries over related objects such as Contact Roles, Sales Teams, and custom objects. Currently, I have to list hundreds of the fields in each of the SOQLs. Also, the function would be broken if the fields are removed/renamed and the newly added fields won't be picked up without updating the SOQL.
I am able to implement the functionality in Ajax by using DescribeSObject(table), but it is very slow if there are many related items. I'm just wondering if I can get original object (dynamic fields) in the s_control (Ajax) first , then pass into Apex code to only do the cloning part (faster)? I got error message with "Type". Here is my code, can you please help?
var clonedOpptyId = sforce.apex.execute('OpptyDeepClone' , 'opptyDeepClone', {arg:orgOppty});
global class OpptyDeepClone {
WebService static String opptyDeepClone(opportunity orgOppty) {
Opportunity clonedOppty = orgOppty.clone(false);
.............
}
}
List<OpportunityShare> newAccessLevels = new List<OpportunityShare>();
for (OpportunityShare oldOpptyShare:[Select o.UserOrGroupId, o.OpportunityAccessLevel From OpportunityShare o where o.OpportunityId =:opptyId]) {
Id userId = oldOpptyShare.UserOrGroupId;
String oldOpptyAccessLevel = oldOpptyShare.OpportunityAccessLevel;
for(OpportunityShare newOpptyShare:[Select o.OpportunityAccessLevel From OpportunityShare o where o.OpportunityId =:newOpptyId and o.UserOrGroupId=:userId limit 1]) {
newOpptyShare.OpportunityAccessLevel = oldOpptyAccessLevel;
newAccessLevels.add(newOpptyShare);
}
}
if(newAccessLevels.size() > 0) {
update newAccessLevels;
}
if(newAccessLevels.size() > 0) {
update newAccessLevels;
}