• Ken_m3
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi,

I'm not a developer but I have been able to copy an S-control someone wrote for me to update certain fields across objects when a page is viewed.  Unfortunately this requires someone view the page (when most likely they will simply run reports to view information)

What I'm looking for is a sample trigger (complete with test coverage if possible) to use as a basis to convert some of my inline s-controls.  Below is a summary of the problem and the s-control that currently meets the need (as long as someone visits the page).  Any help in converting this to a trigger would be appreciated.  My intention is then to replicate the trigger in a similar fashion to the way I have the S-control

Cheers
Ken

In the following example (which is just one of the scontrols, calculated fields, and workflows used in the process):
  • project is master detail to stock
  • project is lookup on forecast
  • stage is an attribute of both stock and forecast.

The inline s control:
  • sums the total number of stock in a stage
  • sums the total price of stock in a stage
  • stamps these values on the forecast record
(there may be many forecast records for a stage as the forecasts are also broken down by period .. eg stage 1 forecast for 2007, stage 1 forecast for 2008 etc)

Ideally the update would be triggered if the number of stock or the price of any stock item changed.

Code:
<script
src="/soap/ajax/10.0/connection.js"
type="text/javascript"></script>

<script>


queryResult = sforce.connection.query(
"SELECT Id, Price__c, Counttotal__c, Stage__c, Project__r.Id FROM Stock__c where Project__r.Id = '{!Projects__c.Id}' and Stage__c = '{!ProjectForecast__c.Stage__c}' ")
queryResultIterator = new sforce.QueryResultIterator(queryResult)

count = 0;
pricesum = 0;


while(queryResultIterator.hasNext())
{ stagelots_Sub = queryResultIterator.next()

count += stagelots_Sub.getFloat('Counttotal__c');
pricesum += stagelots_Sub.getFloat('Price__c');

}
fcast = new sforce.SObject("ProjectForecast__c")
fcast.Id = "{!ProjectForecast__c.Id}"
fcast.Stagepricesum__c = pricesum;
fcast.StageLots__c = count;

result = sforce.connection.update([fcast])


</script>

 

 

Will force.com ide work in os x (Leopard) ?

thought I'd check before downloading.

Cheers
Ken
  • February 26, 2008
  • Like
  • 0
As our salespeople work on weekends we report activities on a Monday to Sunday basis.

I am trying to create a custom field, based on the activity date but I can't seem to access this field in formulas - is this correct?  Basically I wanted to create a custom field "week ending" - something like the following:

CASE( MOD( DATEVALUE(ActivityDate) - DATE(1900, 1, 7), 7),
0, DATEVALUE(ActivityDate),
1, DATEVALUE(ActivityDate) + 6,
2, DATEVALUE(ActivityDate) + 5,
3, DATEVALUE(ActivityDate) + 4,
4, DATEVALUE(ActivityDate) + 3,
5, DATEVALUE(ActivityDate) + 2,
6, DATEVALUE(ActivityDate) + 1,
DATEVALUE(ActivityDate))

so that I could group by 'week ending' in reports.  The formula works fine if I use CreatedDate but sadly we have some paperbased activities that don't get entered into the system until the following week, and using CreatedDate provides inaccurate results.

I'm open to suggestions (short of modifying the report every week) if anyone has a better idea but I really need to be able to show the activities that happened in a given timeframe - from Monday to Sunday

Cheers
Ken
  • February 20, 2008
  • Like
  • 0
Hi,
We use the Excel Connector to update Opportunity records with quote values from an estimation spreadsheet.  It has worked fine for about 4 months but now won't update numeric fields.  Dates, currency and text all still work fine.
 
Any ideas?
 
Thanks.
  • February 21, 2008
  • Like
  • 0
As our salespeople work on weekends we report activities on a Monday to Sunday basis.

I am trying to create a custom field, based on the activity date but I can't seem to access this field in formulas - is this correct?  Basically I wanted to create a custom field "week ending" - something like the following:

CASE( MOD( DATEVALUE(ActivityDate) - DATE(1900, 1, 7), 7),
0, DATEVALUE(ActivityDate),
1, DATEVALUE(ActivityDate) + 6,
2, DATEVALUE(ActivityDate) + 5,
3, DATEVALUE(ActivityDate) + 4,
4, DATEVALUE(ActivityDate) + 3,
5, DATEVALUE(ActivityDate) + 2,
6, DATEVALUE(ActivityDate) + 1,
DATEVALUE(ActivityDate))

so that I could group by 'week ending' in reports.  The formula works fine if I use CreatedDate but sadly we have some paperbased activities that don't get entered into the system until the following week, and using CreatedDate provides inaccurate results.

I'm open to suggestions (short of modifying the report every week) if anyone has a better idea but I really need to be able to show the activities that happened in a given timeframe - from Monday to Sunday

Cheers
Ken
  • February 20, 2008
  • Like
  • 0