• Amanda Jones
  • NEWBIE
  • 70 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 13
    Replies
I'm writing a formula field and need a little help to get it just right.

Here is the formula:

IF(( CloseDate )<=DATE(YEAR((CloseDate)),Month((CloseDate)),15),15,0)

The problem is that the formula is returning records for every year and I only want it return records for the current year. I have tried using the Today() function but I am not putting it in the right place.

Please help!

Thanks in advance.


 
Hello!
So I have a big hairy formula that just keeps getting bigger.

I know that I can use the case function to reduce the compilation size, but can't figure out how to write it.

Here is the monster:

ISPICKVAL(Status, "Cancelled"),0,

IF((

ISPICKVAL (City__c,"Dallas, TX")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c,"Des Moines, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Kansas City, MO")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Sioux Falls, SD")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Ocean Beach, CA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Storm Lake, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Phoenix, AZ")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Las Vegas, NV")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Chicago, IL")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(City__c, "Omaha, NE")&&NumberSent>=10 && UP_Auto_Number_of_Nights__c=2||
ISPICKVAL(City__c, "Lincoln, NE")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4
), 20.00*NumberSent,


IF(VALUE(TEXT(Year__c))>=2018 &&ISPICKVAL(City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c,"Jordan")&& NOT(ISPICKVAL(Type, "JAP")), 165.00,

IF (VALUE(TEXT(Year__c))<=2018 &&ISPICKVAL(City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c, "Marcus")&&NOT(ISPICKVAL(Type, "JAP")),75.00,

IF (VALUE(TEXT(Year__c))>=2019 &&ISPICKVAL(City__c,"Omaha, NE"),170.00,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent>10 ,5.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent<=10,5.00*10,

IF (UP_Auto_Number_of_Nights__c=2&& NumberSent<=10&&NOT(ISPICKVAL(Type, "JAP")), 15.00*10,

IF (UP_Auto_Number_of_Nights__c=2 && NumberSent>10&&NOT(ISPICKVAL(Type, "JAP")),15.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent<=10, 15.00*10,

IF (ISPICKVAL(Type, "JAP") &&  NumberSent<=9 && UP_Auto_Number_of_Nights__c=2, 200.00,

IF (ISPICKVAL(Type, "JAP") &&  NumberSent<=9 && UP_Auto_Number_of_Nights__c=5, 250.00,

IF( ISPICKVAL(City__c, "Omaha, NE")&&NumberSent>=10 && UP_Auto_Number_of_Nights__c=5&&ISPICKVAL(Type, "JAP"),25.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent>10,15.00*NumberSent,

 20.00*10

))))))))))))))

+
IF(Extra_Night__c=True,15.00,0)




Can anyone help me slay it? :-)



 
Hello!

I am trying to update a formula field so that one if statement adds a dollar amount to all of the others. 

Here is the statement that should apply to all of the others IF(Extra_Night__c =True), 15.00

But I can't get it to work when I add it in. When I check the Extra Night box, it only returns the 15.00 value, not the 15.00 plus the other amounts.

IF( 

ISPICKVAL(Status, "Cancelled"),0, 

IF((

ISPICKVAL (UP_City__c,"Dallas, TX")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c,"Des Moines, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4|| 
ISPICKVAL(UP_City__c, "Kansas City, MO")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4|| 
ISPICKVAL(UP_City__c, "Sioux Falls, SD")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Ocean Beach, CA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Storm Lake, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Phoenix, AZ")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Las Vegas, NV")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Chicago, IL")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Lincoln, NE")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4
), 20.00*NumberSent, 

IF(VALUE(TEXT(Year__c))>=2018 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c,"Jordan"), 90.00,

IF (VALUE(TEXT(Year__c))<=2018 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c, "Marcus"),75.00,

IF (VALUE(TEXT(Year__c))>=2019 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c, "Marcus"),80.00,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent>10 ,5.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent<=10,5.00*10,

IF (UP_Auto_Number_of_Nights__c=2&& NumberSent<=10, 15.00*10,

IF (UP_Auto_Number_of_Nights__c=2 && NumberSent>10 ,15.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent<=10, 15.00*10,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent>10 ,15.00*NumberSent,

 20.00*10 


)))))))))))
Hello!

Need a little help here.

I have several formula fields on an object that I need to condense to one field. I have several because compilation limits prevented me from including all of my IF statements in one formula field, so now I decided to use a workflow rule.

Below I have pasted all of the formulas that are currently calculating values on four different formula fields.

How do I string them together so that I can get each calculation to run in one field? It's named Total Cost.

Thanks in advance!


IF(Couple__c=True&&ISPICKVAL(Deployment_No__c, "1")&&New_Pricing__c=False,(STIMonthlyCostcurrency__c+ STIDailyCostcurrency__c+GA_Addtl_Cost__c+91)*2+ Donor_Elf_Fee__c,0)

IF(Couple__c=True&&ISPICKVAL(Deployment_No__c, "1")&&New_Pricing__c=True,(GAMonthlyCostcurrency__c + GADailyCostcurrency__c +GA_Addtl_Cost__c+91)*2+ Donor_Elf_Fee__c,0)

IF(ISPICKVAL(Deployment_No__c,"1")&&ISBLANK(StartDate)|| New_Pricing__c=True||Couple__c =True||NOT(ISPICKVAL(Deployment_No__c,"1"))&&Total_Amount_Received__c>26,0,91+STIMonthlyCostcurrency__c+ STIDailyCostcurrency__c+ GA_Addtl_Cost__c-Applied_Credit__c+ Donor_Elf_Fee__c)

IF(ISPICKVAL(Deployment_No__c,"1")&&ISBLANK(StartDate)||Couple__c =True||NOT(ISPICKVAL(Deployment_No__c,"1"))||New_Pricing__c=False&& Total_Amount_Received__c>26,0,91+GAMonthlyCostcurrency__c + GADailyCostcurrency__c + GA_Addtl_Cost__c-Applied_Credit__c+ Donor_Elf_Fee__c)

IF(Couple__c=True&&NOT(ISPICKVAL( Deployment_No__c,"1"))&&New_Pricing__c=False,(STIMonthlyCostcurrency__c+ STIDailyCostcurrency__c+GA_Addtl_Cost__c)*2+Donor_Elf_Fee__c,0)

IF(Couple__c=True&&NOT(ISPICKVAL( Deployment_No__c,"1")),(GAMonthlyCostcurrency__c + GADailyCostcurrency__c +GA_Addtl_Cost__c)*2+Donor_Elf_Fee__c,0)

IF(Couple__c=True||(ISPICKVAL(Deployment_No__c,"1"))||New_Pricing__c=True&&NOT(ISPICKVAL(Deployment_No__c,"1")),0, STIMonthlyCostcurrency__c + STIDailyCostcurrency__c +GA_Addtl_Cost__c-Applied_Credit__c+ Donor_Elf_Fee__c)

IF(Couple__c=False&&NOT(ISPICKVAL(Deployment_No__c,"1"))||New_Pricing__c=True&&NOT(ISPICKVAL(Deployment_No__c,"1")), GAMonthlyCostcurrency__c + GADailyCostcurrency__c +GA_Addtl_Cost__c-Applied_Credit__c+ Donor_Elf_Fee__c,
I'm stumped. I have written the following formula on a currency field:

IF(ISBLANK(TEXT(Assessment_Override__c)),(Amount*Assessment__c)+ CorrectCC_Fee__c,(Amount*VALUE(TEXT(Assessment_Override__c))+ CorrectCC_Fee__c))

It works great, except, I have a checkbox field that, when it equals true, I want this formula to return a value of zero. I just can't figure out how to write it. I think it should be an IF/OR statement, or maybe a CASE, but all of the examples I find aren't quite right.

The name of the checkbox field is  Do_Not_Assess__c.

Your superior brain power is much appreciated.
Hello!

I have written a formula and now need to condense it to get it to run in my org. I think the CASE function may help me here, but am not sure how to write it.

Here is the current statement:

IF(NOT(ISPICKVAL(Country__c,"Costa Rica")),
STMAmountBase__c-450,

IF(
 BEGINS(Name, "Micro-trip"),STMAmountBase__c-90,
STMAmountBase__c-275))

The compile size is  (5,557 characters). I need it be 5000 or less of course. 

Looking for bigger brains than mine. :)

Thanks!
Hello everyone,

I recently created a new user with very limited access in  our SF org. As a result I changed the permissions for one object (Donations) to private. It was always public before.

Everyone else still has full access to the records on that object, but for this one particular user, it appears that I now need to go in and grant access to each record (there are over 400) by clicking the sharing button.

I thought perhaps if the button were on the list view, I might be able to select several at once and then do a mass update to add the user and grant access to the records. However I am not quite sure how to go about it.

I tried a simple button with URL as the content source, but wasn't sure about the parameters to use for the record IDs to get the button to pull variable records. Here is the url when I click the sharing button:https://na12.salesforce.com/p/share/OppSharingEdit?parentId=(recordID)&retURL=%2Fp%2Fshare%2FOppSharingDetail%3FparentId%(recordID)

Or perhaps I should use a button with onclick javascript as the content source, but have no idea how to start writing the code for that.

Any ideas, guidance or help articles are much appreciated.

Thank you!

 
 
Hello!

I have a question that I am pretty sure is an easy fix, only I can't seem to wrap my brain around the solution, so I am deferring to bigger brains than mine. :)

I have two formula fields. One calculates the number of months of a mission trip and the other returns a cost based on the number of months. what I need is a modification to one or both formulas that will return the cost for One month even if the dates calculate to Less than 30 days.

Here is the formula that caculates the length of time
(EndDate - StartDate +1)/30

Here is the formula that calculates the cost for the length of time:

STIMonths__c *CASE(TEXT(Country__c),"Argentina", 750.00,
"Bolivia", 625.00,
"Colombia",650.00,
"Costa Rica", 685.00,
"El Salvador", 685.00,
"Guatemala", 685.00,
"Tijuana, MX", 650.00,
"Tuxpan, MX", 650.00,
"Nicaragua", 685.00,
"Peru", 650.00, NULL)

Any guidance is hugely appreciated!
I have a huge formula compiled size 4,628 characters that I am trying to condense.
I think I can do it by stating the negative of a picklist value, but I'm not sure how to do it. Here is my formula:

CASE(text(Deployment_No__c),
"2",STI_Monthly_Cost__c + Cost_for_Discounted_Adults__c + Cost_of_Children__c + Addtl_Lodging_Cost_Total__c + Addtl_Cost_Incidentals__c + STI_Daily_Cost__c-Applied_Credit__c,
"3",STI_Monthly_Cost__c + Cost_for_Discounted_Adults__c + Cost_of_Children__c + Addtl_Lodging_Cost_Total__c + Addtl_Cost_Incidentals__c + STI_Daily_Cost__c-Applied_Credit__c,
0)

I want to rewrite the formula so that it will calculate if the picklist value is NOT "1". That way I can use each of them only once.

Looking forward to your brilliant answers! :)
I have a formula that I think would work, but I can't get it to compile, it's too large. Is there a way to use the CASE function to make it smaller?

IF(
    NOT(
        OR(ISBLANK(First_Time_STI_Total_Cost__c),ISNULL(First_Time_STI_Total_Cost__c))
    ),
    First_Time_STI_Total_Cost__c-Total_Amount_Received__c,
    IF(
        NOT(
            OR(ISBLANK(Repeat_STI_Total_Cost__c),ISNULL(Repeat_STI_Total_Cost__c))
        ),
        Repeat_STI_Total_Cost__c-Total_Amount_Received__c,
        null
    )
)
I have two currency fields on my campaigns object. If one field is calculated, by default the other is not and has a zero balance.

I need to write a formula that decides when a field is not equal to zero and then performs a calculation on that field.

Here is what I have so far:

IF(NOT(
ISBLANK(First_Time_STI_Total_Cost__c)),
First_Time_STI_Total_Cost__c-Total_Amount_Received__c,
null
)

OR

IF(NOT(
ISBLANK(Repeat_STI_Total_Cost__c)),
Repeat_STI_Total_Cost__c-Total_Amount_Received__c,
null
)
But it doesn't work. Please help.
I am stumped.

I have written a trigger that should complete a rollup summary on two currency fields on my Campaigns object. When I run the test class it passes and I get 100% code coverage. But when I validate in my production org I get the following error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RollupTotalAmountsandCCFees: execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null. Trigger.RollupTotalAmountsandCCFees: line 57, column 1: []
Stack Trace: Class.TEST_TotalAmountReceived.testTotalAmountReceived: line 32, column 1

Here is my trigger:
/* **********************************************************************************
 *
 * Trigger: Rollup Total Amounts and CC Fees
 * Created by:Amanda Jones
 *
 * Purpose/Methods:
 * - This trigger rolls up all of the Donations (Opportunities) and credit card fees into two
 * - currency fields on a Campaign. It is executed after an insert, update or delete of an
 * - opportunity
 *
 * Unit Test:
 * - TEST_RollupTotalAmountsandCCFees Apex Class
 *
 ************************************************************************************** */
 
trigger RollupTotalAmountsandCCFees on Opportunity (after insert, after update , after delete )
{

  // gather campaigns from Opps being updated
  List<String> campIds = new List<String>();
  List<String> campIdRemoved = new List<String>();

    if(Trigger.isInsert || Trigger.isUpdate)
    {
        for (Opportunity o : trigger.new)
        {
            if (o.CampaignID != null && (trigger.isInsert || o.Amount != trigger.oldMap.get(o.id).Amount))
                campIds.add(o.CampaignId);
        }
    }
    else if (Trigger.isDelete)
    {
        for (Opportunity o : trigger.old)
        {
            if ( o.CampaignID != null )
                campIds.add(o.CampaignId);
        }
    }  
  
  if (campIds.size() > 0)
  {
  
      Map<id, Campaign> campaigns = new Map<id, Campaign>([SELECT id FROM Campaign WHERE id =: campIds]);
      
      // initialize Campaign.Total_Amount_Received__c and CreditCardFee__c to zero on all campaigns
      for (Campaign c : campaigns.values())
       c.Total_Amount_Received__c= 0;
      for (Campaign c : campaigns.values())
       c.CreditCardFee__c= 0;
      
      // add all Opp.Total_Amount_Received__c and CreditCardFee__c to campaigns
        for (Opportunity o : [SELECT id, Amount, CorrectCC_Fee__c, CampaignId FROM Opportunity WHERE CampaignId =: campIds])

        {
            Campaign c = campaigns.get(o.CampaignId);
            c.Total_Amount_Received__c += o.Amount;
            c.CreditCardFee__c += o.CorrectCC_Fee__c;
        }
  
    // update campaigns
    update campaigns.values();
  }
   
}

And here is the test class:
/* **********************************************************************************
 *
 * Trigger Unit Test: Rollup Total Amounts and CC Fees
 * Created by: Amanda Jones
 *
 * Goal: Testing Trigger - RollupTotalAmountsandCCFees for Campaign Rollup
 *
 * Coverage: 100%
 *
 *
 *********************************************************************************** */
 
@isTest
 private class TEST_RollupTotalAmountsandCCFees {
  
static testMethod void testRollupTotalAmountsandCCFees()
{
  
    // Create a test campaign
    Campaign c = new Campaign ();
    c.Name = 'UnitTest';
    insert c;
    System.assert(c != null);
      
    // Create a test opportunity for the campaign
    Opportunity o = new Opportunity ();
    o.Name = 'UnitTest';
    o.StageName = 'Closed Won';
    o.CloseDate = Date.Today();
    o.CampaignID = c.ID;
    o.Payment_Method__c = 'card payment';
    o.Amount = 100.00;
    insert o;
    System.assert(o != null);
       
    // Retrieve the Campaign
    Campaign c1 = [SELECT Total_Amount_Received__c FROM Campaign WHERE Id = :c.Id];
    System.assertEquals (100.00, c1.Total_Amount_Received__c );
    Campaign c2 = [SELECT CreditCardFee__c FROM Campaign WHERE Id = :c.Id];
    System.assertEquals (3.00, c2.CreditCardFee__c );
    
    
    Delete o;
    

}
}

Ideas would be most appreciated.

Thank you!
I have what I think is a quick question about fixing a trigger that I've written. 

The total donations are being calculated in a currency field on the Campaigns object. The problem is that when I delete one of the donations, the field does not recalculate to show the reduced amount.

How do I need to change my code to make this happen? 

Thanks in advance for your help!

Here is my code:

/* **********************************************************************************
 *
 * Trigger: Total Amount Received for Campaign Rollup
 * Created by:Amanda Jones
 *
 * Purpose/Methods:
 * - This trigger rolls up all of the Donations (Opportunities) into a
 * - currency field on a Campaign. It is executed after an insert or an update of
 * - opportunity
 *
 * Unit Test:
 * - TEST_TotalAmountReceived Apex Class
 *
 ************************************************************************************** */
 
trigger TotalAmountReceivedforCampaign on Opportunity (after insert, after update) {
 
  // gather campaigns from Opps being updated
  List<String> campIds = new List<String>();
 
  for (Opportunity o : trigger.new){
   if (o.CampaignID != null && (trigger.isInsert || o.Amount != trigger.oldMap.get(o.id).Amount))
   campIds.add(o.CampaignId);
  }
 
  if (campIds.size() > 0) {
 
  Map<id, Campaign> campaigns = new Map<id, Campaign>([SELECT id FROM Campaign WHERE id =: campIds]);
 
  // initialize Campaign.Total_Amount_Received__c to zero on all campaigns
  for (Campaign c : campaigns.values())
   c.Total_Amount_Received__c= 0;
 
  // add all Opp.Amount_Received__c to campaigns
  for (Opportunity o : [SELECT id, Amount, CampaignId FROM Opportunity WHERE CampaignId =: campIds]){
   Campaign c = campaigns.get(o.CampaignId);
   c.Total_Amount_Received__c += o.Amount;
  }
 
  // update campaigns
  update campaigns.values();
  }
}
I'm writing a formula field and need a little help to get it just right.

Here is the formula:

IF(( CloseDate )<=DATE(YEAR((CloseDate)),Month((CloseDate)),15),15,0)

The problem is that the formula is returning records for every year and I only want it return records for the current year. I have tried using the Today() function but I am not putting it in the right place.

Please help!

Thanks in advance.


 
Hello!

I am trying to update a formula field so that one if statement adds a dollar amount to all of the others. 

Here is the statement that should apply to all of the others IF(Extra_Night__c =True), 15.00

But I can't get it to work when I add it in. When I check the Extra Night box, it only returns the 15.00 value, not the 15.00 plus the other amounts.

IF( 

ISPICKVAL(Status, "Cancelled"),0, 

IF((

ISPICKVAL (UP_City__c,"Dallas, TX")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c,"Des Moines, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4|| 
ISPICKVAL(UP_City__c, "Kansas City, MO")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4|| 
ISPICKVAL(UP_City__c, "Sioux Falls, SD")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Ocean Beach, CA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Storm Lake, IA")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Phoenix, AZ")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Las Vegas, NV")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Chicago, IL")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4||
ISPICKVAL(UP_City__c, "Lincoln, NE")&&NumberSent>10 && UP_Auto_Number_of_Nights__c>= 4
), 20.00*NumberSent, 

IF(VALUE(TEXT(Year__c))>=2018 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c,"Jordan"), 90.00,

IF (VALUE(TEXT(Year__c))<=2018 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c, "Marcus"),75.00,

IF (VALUE(TEXT(Year__c))>=2019 &&ISPICKVAL(UP_City__c,"Omaha, NE")&&ISPICKVAL(Coordinator_First_Name__c, "Marcus"),80.00,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent>10 ,5.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c<1 && NumberSent<=10,5.00*10,

IF (UP_Auto_Number_of_Nights__c=2&& NumberSent<=10, 15.00*10,

IF (UP_Auto_Number_of_Nights__c=2 && NumberSent>10 ,15.00*NumberSent,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent<=10, 15.00*10,

IF (UP_Auto_Number_of_Nights__c=3&& NumberSent>10 ,15.00*NumberSent,

 20.00*10 


)))))))))))
I'm stumped. I have written the following formula on a currency field:

IF(ISBLANK(TEXT(Assessment_Override__c)),(Amount*Assessment__c)+ CorrectCC_Fee__c,(Amount*VALUE(TEXT(Assessment_Override__c))+ CorrectCC_Fee__c))

It works great, except, I have a checkbox field that, when it equals true, I want this formula to return a value of zero. I just can't figure out how to write it. I think it should be an IF/OR statement, or maybe a CASE, but all of the examples I find aren't quite right.

The name of the checkbox field is  Do_Not_Assess__c.

Your superior brain power is much appreciated.
Hello!

I have written a formula and now need to condense it to get it to run in my org. I think the CASE function may help me here, but am not sure how to write it.

Here is the current statement:

IF(NOT(ISPICKVAL(Country__c,"Costa Rica")),
STMAmountBase__c-450,

IF(
 BEGINS(Name, "Micro-trip"),STMAmountBase__c-90,
STMAmountBase__c-275))

The compile size is  (5,557 characters). I need it be 5000 or less of course. 

Looking for bigger brains than mine. :)

Thanks!
Hello!

I have a question that I am pretty sure is an easy fix, only I can't seem to wrap my brain around the solution, so I am deferring to bigger brains than mine. :)

I have two formula fields. One calculates the number of months of a mission trip and the other returns a cost based on the number of months. what I need is a modification to one or both formulas that will return the cost for One month even if the dates calculate to Less than 30 days.

Here is the formula that caculates the length of time
(EndDate - StartDate +1)/30

Here is the formula that calculates the cost for the length of time:

STIMonths__c *CASE(TEXT(Country__c),"Argentina", 750.00,
"Bolivia", 625.00,
"Colombia",650.00,
"Costa Rica", 685.00,
"El Salvador", 685.00,
"Guatemala", 685.00,
"Tijuana, MX", 650.00,
"Tuxpan, MX", 650.00,
"Nicaragua", 685.00,
"Peru", 650.00, NULL)

Any guidance is hugely appreciated!
I have a huge formula compiled size 4,628 characters that I am trying to condense.
I think I can do it by stating the negative of a picklist value, but I'm not sure how to do it. Here is my formula:

CASE(text(Deployment_No__c),
"2",STI_Monthly_Cost__c + Cost_for_Discounted_Adults__c + Cost_of_Children__c + Addtl_Lodging_Cost_Total__c + Addtl_Cost_Incidentals__c + STI_Daily_Cost__c-Applied_Credit__c,
"3",STI_Monthly_Cost__c + Cost_for_Discounted_Adults__c + Cost_of_Children__c + Addtl_Lodging_Cost_Total__c + Addtl_Cost_Incidentals__c + STI_Daily_Cost__c-Applied_Credit__c,
0)

I want to rewrite the formula so that it will calculate if the picklist value is NOT "1". That way I can use each of them only once.

Looking forward to your brilliant answers! :)
I have a formula that I think would work, but I can't get it to compile, it's too large. Is there a way to use the CASE function to make it smaller?

IF(
    NOT(
        OR(ISBLANK(First_Time_STI_Total_Cost__c),ISNULL(First_Time_STI_Total_Cost__c))
    ),
    First_Time_STI_Total_Cost__c-Total_Amount_Received__c,
    IF(
        NOT(
            OR(ISBLANK(Repeat_STI_Total_Cost__c),ISNULL(Repeat_STI_Total_Cost__c))
        ),
        Repeat_STI_Total_Cost__c-Total_Amount_Received__c,
        null
    )
)
I have two currency fields on my campaigns object. If one field is calculated, by default the other is not and has a zero balance.

I need to write a formula that decides when a field is not equal to zero and then performs a calculation on that field.

Here is what I have so far:

IF(NOT(
ISBLANK(First_Time_STI_Total_Cost__c)),
First_Time_STI_Total_Cost__c-Total_Amount_Received__c,
null
)

OR

IF(NOT(
ISBLANK(Repeat_STI_Total_Cost__c)),
Repeat_STI_Total_Cost__c-Total_Amount_Received__c,
null
)
But it doesn't work. Please help.
I am stumped.

I have written a trigger that should complete a rollup summary on two currency fields on my Campaigns object. When I run the test class it passes and I get 100% code coverage. But when I validate in my production org I get the following error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, RollupTotalAmountsandCCFees: execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null. Trigger.RollupTotalAmountsandCCFees: line 57, column 1: []
Stack Trace: Class.TEST_TotalAmountReceived.testTotalAmountReceived: line 32, column 1

Here is my trigger:
/* **********************************************************************************
 *
 * Trigger: Rollup Total Amounts and CC Fees
 * Created by:Amanda Jones
 *
 * Purpose/Methods:
 * - This trigger rolls up all of the Donations (Opportunities) and credit card fees into two
 * - currency fields on a Campaign. It is executed after an insert, update or delete of an
 * - opportunity
 *
 * Unit Test:
 * - TEST_RollupTotalAmountsandCCFees Apex Class
 *
 ************************************************************************************** */
 
trigger RollupTotalAmountsandCCFees on Opportunity (after insert, after update , after delete )
{

  // gather campaigns from Opps being updated
  List<String> campIds = new List<String>();
  List<String> campIdRemoved = new List<String>();

    if(Trigger.isInsert || Trigger.isUpdate)
    {
        for (Opportunity o : trigger.new)
        {
            if (o.CampaignID != null && (trigger.isInsert || o.Amount != trigger.oldMap.get(o.id).Amount))
                campIds.add(o.CampaignId);
        }
    }
    else if (Trigger.isDelete)
    {
        for (Opportunity o : trigger.old)
        {
            if ( o.CampaignID != null )
                campIds.add(o.CampaignId);
        }
    }  
  
  if (campIds.size() > 0)
  {
  
      Map<id, Campaign> campaigns = new Map<id, Campaign>([SELECT id FROM Campaign WHERE id =: campIds]);
      
      // initialize Campaign.Total_Amount_Received__c and CreditCardFee__c to zero on all campaigns
      for (Campaign c : campaigns.values())
       c.Total_Amount_Received__c= 0;
      for (Campaign c : campaigns.values())
       c.CreditCardFee__c= 0;
      
      // add all Opp.Total_Amount_Received__c and CreditCardFee__c to campaigns
        for (Opportunity o : [SELECT id, Amount, CorrectCC_Fee__c, CampaignId FROM Opportunity WHERE CampaignId =: campIds])

        {
            Campaign c = campaigns.get(o.CampaignId);
            c.Total_Amount_Received__c += o.Amount;
            c.CreditCardFee__c += o.CorrectCC_Fee__c;
        }
  
    // update campaigns
    update campaigns.values();
  }
   
}

And here is the test class:
/* **********************************************************************************
 *
 * Trigger Unit Test: Rollup Total Amounts and CC Fees
 * Created by: Amanda Jones
 *
 * Goal: Testing Trigger - RollupTotalAmountsandCCFees for Campaign Rollup
 *
 * Coverage: 100%
 *
 *
 *********************************************************************************** */
 
@isTest
 private class TEST_RollupTotalAmountsandCCFees {
  
static testMethod void testRollupTotalAmountsandCCFees()
{
  
    // Create a test campaign
    Campaign c = new Campaign ();
    c.Name = 'UnitTest';
    insert c;
    System.assert(c != null);
      
    // Create a test opportunity for the campaign
    Opportunity o = new Opportunity ();
    o.Name = 'UnitTest';
    o.StageName = 'Closed Won';
    o.CloseDate = Date.Today();
    o.CampaignID = c.ID;
    o.Payment_Method__c = 'card payment';
    o.Amount = 100.00;
    insert o;
    System.assert(o != null);
       
    // Retrieve the Campaign
    Campaign c1 = [SELECT Total_Amount_Received__c FROM Campaign WHERE Id = :c.Id];
    System.assertEquals (100.00, c1.Total_Amount_Received__c );
    Campaign c2 = [SELECT CreditCardFee__c FROM Campaign WHERE Id = :c.Id];
    System.assertEquals (3.00, c2.CreditCardFee__c );
    
    
    Delete o;
    

}
}

Ideas would be most appreciated.

Thank you!
I have what I think is a quick question about fixing a trigger that I've written. 

The total donations are being calculated in a currency field on the Campaigns object. The problem is that when I delete one of the donations, the field does not recalculate to show the reduced amount.

How do I need to change my code to make this happen? 

Thanks in advance for your help!

Here is my code:

/* **********************************************************************************
 *
 * Trigger: Total Amount Received for Campaign Rollup
 * Created by:Amanda Jones
 *
 * Purpose/Methods:
 * - This trigger rolls up all of the Donations (Opportunities) into a
 * - currency field on a Campaign. It is executed after an insert or an update of
 * - opportunity
 *
 * Unit Test:
 * - TEST_TotalAmountReceived Apex Class
 *
 ************************************************************************************** */
 
trigger TotalAmountReceivedforCampaign on Opportunity (after insert, after update) {
 
  // gather campaigns from Opps being updated
  List<String> campIds = new List<String>();
 
  for (Opportunity o : trigger.new){
   if (o.CampaignID != null && (trigger.isInsert || o.Amount != trigger.oldMap.get(o.id).Amount))
   campIds.add(o.CampaignId);
  }
 
  if (campIds.size() > 0) {
 
  Map<id, Campaign> campaigns = new Map<id, Campaign>([SELECT id FROM Campaign WHERE id =: campIds]);
 
  // initialize Campaign.Total_Amount_Received__c to zero on all campaigns
  for (Campaign c : campaigns.values())
   c.Total_Amount_Received__c= 0;
 
  // add all Opp.Amount_Received__c to campaigns
  for (Opportunity o : [SELECT id, Amount, CampaignId FROM Opportunity WHERE CampaignId =: campIds]){
   Campaign c = campaigns.get(o.CampaignId);
   c.Total_Amount_Received__c += o.Amount;
  }
 
  // update campaigns
  update campaigns.values();
  }
}