我在salesforce上开发了一个apex API,它在CSV数据列表上执行SOQL。它一直运行到昨天,在对SOQL查询后面的代码进行一些更改后,我开始得到一个奇怪的500错误:
[{"的errorCode":" APEX_ERROR""消息":" System.UnexpectedException: common.exception.SfdcSqlException:ORA-01460:未实现或 请求不合理的转换\ n \ n \ n选择/ SampledPrequery / sum(term0)\" cnt0 \",\ nsum(term1)\" cnt1 \",\ ncount(*) \" totalcount \",\ nsum(term0 * term1)\"合并\" \ n from(select / * + 有序的use_nl(t_c1) / \ n((t_c1.deleted =' 0')的情况,然后是1,否则0 结束)term0,\ n(情况何时(上(t_c1.val18)=?)然后1其他0结束) term1 \ n from(select / + index(sampleTab AKENTITY_SAMPLE) * / \ nentity_id \ n from core.entity_sample sampleTab \ nwhere organization_id =' 00Dq0000000AMfz' \ nand key_prefix =?\ nand rownum< = ?)sampleTab,\ ncore.custom_entity_data t_c1 \ nwhere t_c1.organization_id =' 00Dq0000000AMfz' \ n和t_c1.key_prefix =?\ nand sampleTab.entity_id = t_c1.custom_entity_data_id)\ n \ nClass.labFlows.queryContacts:第13行, 第1列\ nClass.labFlows.fhaQuery:第6行,列 1 \ nClass.zAPI.doPost:第10行,第1列"}]
zAPI.doPost()只是我们的路由器类,它接收后有效负载以及请求的操作。然后它调用操作请求的任何函数。在这种情况下,调用是labFlows.queryContacts():
Public static Map<string,List<string>> queryContacts(string[] stringArray){
//First get the id to get to the associative entity, Contact_Deals__c id
List<Contact_Deals__c> dealQuery = [SELECT id, Deal__r.id, Deal__r.FHA_Number__c, Deal__r.Name, Deal__r.Owner.Name
FROM Contact_Deals__c
Where Deal__r.FHA_Number__c in :stringArray];
//Using the id in the associative entity, grab the contact information
List<Contact_Deals__c> contactQuery = [Select Contact__r.Name, Contact__r.Id, Contact__r.Owner.Name, Contact__r.Owner.Id, Contact__r.Rule_Class__c, Contact__r.Primary_Borrower_Y_N__c
FROM contact_deals__c
WHERE Id in :dealQuery];
//Grab all deal id's
Map<string,List<string>> result = new Map<string,List<string>>();
for(Contact_Deals__c i:dealQuery){
List<string> temp = new list<string>();
temp.add(i.Deal__r.Id);
temp.add(i.Deal__r.Owner.Name);
temp.add(i.Deal__r.FHA_Number__c);
temp.add(i.Deal__r.Name);
for(Contact_Deals__c j:contactQuery){
if(j.id == i.id){
//This doesn't really help if there are multiple primary borrowers on a deal - but that should be a SF worflow rule IMO
if(j.Contact__r.Primary_Borrower_Y_N__c == 'Yes'){
temp.add(j.Contact__r.Owner.Id);
temp.add(j.Contact__r.Id);
temp.add(j.Contact__r.Name);
temp.add(j.Contact__r.Owner.Name);
temp.add(j.Contact__r.Rule_Class__c);
break;
}
}
}
result.put(i.Deal__r.id, temp);
}
return result;
}
我唯一改变的是移动临时列表以在内循环之前添加元素(之前的temp只会从内循环中捕获内容)。上面的错误是引用第13行,这是第一个SOQL调用:
List<Contact_Deals__c> dealQuery = [SELECT id, Deal__r.id, Deal__r.FHA_Number__c, Deal__r.Name, Deal__r.Owner.Name
FROM Contact_Deals__c
Where Deal__r.FHA_Number__c in :stringArray];
我已经在顶级匿名窗口中测试了这个功能,它运行得很好:
string a = '00035398,00035401';
string result = zAPI.doPost(a, 'fhaQuery');
system.debug(result);
结果:
13:36:54:947 USER_DEBUG [5] | DEBUG | {&#34; a09d000000HRvBAD&#34;:[&#34; a09d000000HRvBAD&#34;&#34; Contacta&#34;&#34; 11111111&#34;&#34;广场 中央 APTS&#34],&#34; a09d000000HsVAD&#34;:[&#34; a09d000000HsVAD&#34;&#34; Contactb&#34;&#34; 22222222&#34;&#34;该 花园&#34;]}
所以这是有效的。下一部分可能是看我调用API的python脚本,
def origQuery(file_name, operation):
csv_text = ""
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
data = json.dumps({
'data' : csv_text,
'operation' : operation
})
results = requests.post(url, headers=headers, data=data)
print results.text
origQuery('myfile.csv', 'fhaQuery')
我已经尝试查找此ORA-01460顶点错误,但我找不到任何可以帮助我解决此问题的内容。
任何人都可以了解这个错误告诉我的事情吗?
非常感谢你们!
答案 0 :(得分:0)
事实证明错误发生在PY脚本中。出于某种原因,以下代码不能正常运行:
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
这返回了一个非常长的字符串,该字符串具有零分隔符。代码中的最后一行是切断分隔符。我需要的是:
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
哪会切断决赛,&#39;
发生错误是因为单个长字符串超过4,000个字符。