2011-07-15 11 views
0

私はSalesforceでタスクを作成し、ユーザの閲覧履歴を追跡してSalesForceに保存する次のコードを用意しています。現在、ユーザーが閲覧した各ページが個別のエントリとして表示されます。ユーザーがページにアクセスするたびにタスクが作成されるのではなく、Browsing_History__cオブジェクトにこれらのエントリをまとめてグループ化したいと思います。C#SalesForceでUpsert関数を使用してカスタムオブジェクトのリンクをバインドするには?

何か助けていただければ幸いです。私はSFをよく知っていません。 :)

private void CreateTaskInSF(string id, string type, string details, string description) 
    { 
     // if there's a similar Event in the past 2 hours, don't add it 
     QueryResult qr = null; 
     try // get events from past 2 hours 
     { 
      qr = Binding.query("Select Details__c from Task WHERE WhoId='" + id + "' and Type__c='" + type + "' and CreatedDate > " + DateTime.UtcNow.AddHours(-2).ToString("s") + "Z"); 
     } 
     catch (Exception e) 
     { 
      return; 
     } 
     bool logged = false; 
     if (qr != null) // if there are Tasks in past 2 hours 
     { 
      sforce.sObject[] browsing = qr.records; 
      if (browsing != null) 
      { 
       // iterate through events to make sure the new Task isn't logged 
       for (int i = 0; i < browsing.Length; i++) 
       { 
        Task currTask = (Task)browsing[i]; 
        if (currTask.Details__c == details) 
        { 
         if (description != "") // is there a description to check for? 
         { 
          string oldTaskDescription = ""; 
          if (currTask.Description != null) 
           oldTaskDescription = currTask.Description; 
          if (oldTaskDescription == description) // if there is a description match 
           logged = true; 
         } 
         else 
          logged = true; // there's no description, so check only on details field 
        } 
       } 
      } 
     } 
     if (logged == true) 
     { 
      return; // if Activity is already logged, don't log it again 
     } 

     else if (type == "Browsing") 
     { 
      QueryResult browsingQuery = null; 
      try // get events from past 2 hours 
      { 
       browsingQuery = Binding.query("Select Web_Browsing__c from Task WHERE WhoId='" + id + "' and Subject='" + type + "' and Details__c='" + details + "' and CreatedDate > " + DateTime.UtcNow.AddHours(-2).ToString("s") + "Z"); 
      } 
      catch 
      { 

      } 

      Boolean createNewBrowsing = false; 
      if (browsingQuery != null) // if there are Tasks in past 2 hours 
      { 
       sforce.sObject[] webBrowsing = browsingQuery.records; 
       if (webBrowsing != null) 
       { 
        //find correct object and update Browsing_History__c 
        //Binding.update 

       } 

       else 
       { 
        createNewBrowsing = true; 
       } 

      } 
      else 
      { 
       createNewBrowsing = true; 
      } 

      if (createNewBrowsing) 
      { 

       Web_Browsing__c newTask = new Web_Browsing__c(); 
       newTask.Lead__c = id; 
       newTask.Browsing_History_255__c = details; 
       newTask.Type__c = type; 

       newTask.Browsing_History__c = details; 
       newTask.CreatedDate = DateTime.Now; 
       //if(type == "Browsing") newTask. = details; 
       //SaveResult[] createResult = Binding.create(new sObject[] { newTask }); 

      try 
      { 
       SaveResult[] createResult = Binding.create(new sObject[] { newTask }); 
      } 
      catch (Exception e) 
      { 
       return; 
      } 

      } 

     } 

     else 
     { 
      // if this new Activity isn't logged, then create a new Activity Task 
      sforce.Task newTask = new sforce.Task(); 
      newTask.WhoId = id; 
      newTask.Subject = type; 
      newTask.Details__c = details; 
      if (description != "") newTask.Description = description; 
      newTask.Status = "Completed"; 
      newTask.Priority = "Normal"; 
      newTask.ActivityDate = DateTime.Now; 
      newTask.ActivityDateSpecified = true; 

      // insert it 
      try 
      { 
       SaveResult[] createResult = Binding.create(new sforce.sObject[] { newTask }); 

      } 
      catch (Exception e) 
      { 
       return; 
      } 
     } 


    } 

答えて

1

閲覧履歴オブジェクトを要求し、タスクではなく参照履歴オブジェクトを作成するコードを更新するようにクエリを更新する必要があります。

Web Services APIドキュメントをまだお持ちでない場合は、java/c#にqueryingcreatingの例があります。

関連する問題