function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rsimmonsrsimmons 

Custom Object formula

I have created a custom object inside the Opportunity tab that is designed to displays individual expenses.  Ultimately I would like to have all these expenses total into a seperate field.  Is it possible to create a formula to do this?
TCAdminTCAdmin
RSimmons,
 
The formula feature doesn't have the ability to pull data from a related list.  You can do this with an sControl if you have some experience with JavaScript.  If not there are people here that would be willing to contract one for you.  I have added a sample below that you may be able to use to do this with some modification.  I think there is an AppExchange application that does this exact thing that you may want to review before putting much more effort into a custom version.  You can contact me at the email below if you want some more information.
 
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>

<script> 
 function initPage() { 
  sforceClient.registerInitCallback(GetProjectData); 
  sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}", true); 
 }// END initPage function
</script> 

<script>
 function GetProjectData() {
  var oppValues = sforceClient.query("SELECT AccountId, Amount, ForecastCategory FROM Opportunity WHERE AccountId = '{!Account.Id}'"); 
  var account = new Sforce.Dynabean("Account");
  account.set("Id", "{!Account.Id}");

  var omitted = 0.0;
  var pipeline = 0.0;
  var bestCase = 0.0;
  var commit = 0.0;
  var closed = 0.0;
  if (oppValues.className == "Fault") { 
   alert("There was an error: " + oppValues.toString()); 
  } else { 
   if (oppValues.size > 0) { 
     for (var i=0;i<oppValues.size;i++) { 
     var dynaBean = oppValues.records[i];
     if(dynaBean.get("AccountId") != null && dynaBean.get("Amount") != null){
      var longId = dynaBean.get("AccountId");
      var shortId = longId.substring(0,15);
      var amount = dynaBean.get("Amount");
      if(shortId == "{!Account.Id}"){
       var storeLongId = longId;
       var type = dynaBean.get("ForecastCategory");
       if(type == "Forecast")
        commit += amount;
       if(type == "Pipeline")
        pipeline += amount;
       if(type == "BestCase")
        bestCase += amount;
       if(type == "Omitted")
        omitted += amount;
       if(type == "Closed")
        closed += amount;
       account.set("Id", storeLongId);
      }// END (related to account) if statement
     }// END (account & amount null( if loop
    }// END for loop
   } else { 
    var textNode = document.createTextNode("No records matched."); 
   }// END noRecord else clause
  }// END projectHours else clause
  account.set("Opportunity_Omitted__c", omitted);
  account.set("Opportunity_Pipeline__c", pipeline);
  account.set("Opportunity_Best_Case__c", bestCase);
  account.set("Opportunity_Commit__c", commit);
  account.set("Opportunity_Closed__c", closed);
  var saveResult = sforceClient.update(account);
  opener.location.reload();
  window.close();
 } 
</script>
</head> 
<body onload="initPage()">

</body> 
</html>
rsimmonsrsimmons

Chris,

Thanks so much for the info, I will give it a try, I may need to contact you for further help.

Thanks again,

RSimmons