Salesforce 如何动态更新对象中的folderID

Salesforce 如何动态更新对象中的folderID,salesforce,apex-code,Salesforce,Apex Code,我有一个需求,我想我必须使用动态DML。但我对动态Apex和动态DML都是新手 当我将使用API调用在Box.com服务器中创建文件夹时,我将得到一个带有文件夹ID的响应。(我能够进行API调用并获得文件夹ID) 我在Account对象中有一个名为“FolderID\uuC”的自定义字段 所以我必须写一个方法,它有两个参数。一个是objecttype,另一个是folderID,它将在特定的objecttype中执行插入操作。(可能是Account,可能是Contact,应该是动态的) 到目前为止

我有一个需求,我想我必须使用动态DML。但我对动态Apex和动态DML都是新手

当我将使用API调用在Box.com服务器中创建文件夹时,我将得到一个带有文件夹ID的响应。(我能够进行API调用并获得文件夹ID)

我在Account对象中有一个名为“FolderID\uuC”的自定义字段

所以我必须写一个方法,它有两个参数。一个是objecttype,另一个是folderID,它将在特定的objecttype中执行插入操作。(可能是Account,可能是Contact,应该是动态的)

到目前为止我所做的: 您应该使用:


您好@Rudra,Salesforce.stackexchange.com上有一个专门针对Salesforce的新stackexchange网站。来加入那边的社区吧!:)是否所有其他对象都有FolderID_uc字段?如果他们不这样做,就没有地方可以提供这些信息。
String IdVar = ApexPages.CurrentPage().getparameters().get('id');  //It will fetch the record ID
String objecttype = IdVar.getSobjectType().getDescribe().getName(); //It will fetch object type from record ID
//By using API call I’m able to get folderID. So I’m having folder ID
public void updateFolderID(String objectType, String folderID){
   //To do
}
String IdVar = ApexPages.CurrentPage().getparameters().get('id');  //It will fetch the record ID
String objecttype = IdVar.getSobjectType().getDescribe().getName(); //It will fetch object type from record ID
//By using API call I’m able to get folderID. So I’m having folder ID
public void updateFolderID(String objectType, String folderID){
  // get type
  Type t = Type.forName(objectType);
  // instantiate using the type iface
  SObject obj = (SObject)t.newInstance();
  // set field value (field must exist in the object)
  obj.put('FolderID__c',folderID);
  insert  obj;
}