• Stephanie_Arce
  • NEWBIE
  • 20 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies
We have SSO setup (OneLogin specifically) and a few users who use OneLogin's Android app to access our Salesforce org. They are used to opening the OneLogin Android app, tapping an icon for our Salesforce org, and then accessing the SF org in what looks like the SF mobile app but without actually having the Salesforce app installed.

I'm not sure when this started happening, but if a user goes through these steps now, any time they try to access a Visualforce page they get this message (screenshot and text below):
"We'd like to open the Salesforce page <url> in a new tab. Because of your browser settings, we need your permission first."
User-added image

If the user taps "Cancel", they get taken back to the last page they were on. If they tap "Open", the page tries to reload and they get the same message again, essentially stuck in a loop.

Some troubleshooting I've done:
- Verified this error doesn't come up in the OneLogin iOS app
- Verified this error doesn't come up in a mobile browser on Android or iOS
- Verified this error doesn't come up in the Salesforce app on Android or iOS

So, I am only seeing this message in the OneLogin Android app. I know it's probably a long shot, but has anyone else seen this issue? Our infrastructure staff who manage OneLogin have opened a ticket with them but so far haven't heard back.

Thank you!
We have a Visualforce tab that users go to and occassionally get "stuck" on at a URL similar to this:

https://cs67.salesforce.com/servlet/servlet.Integration?lid=01r0n000000D6k3&ic=1&linkToken=VmpFPSxNakF4T0Mwd09DMHhNMVF5TURveE5Eb3pNUzR5TnpsYSx3YmJfXzV3ZnVOREVtdXlTcm9ldWFwLFlXWmtNR0po

The Visualforce page ends up not loading. Normally, they'll see this URL for just a second and then get directed to the Visualforce page, for example: https://c.cs67.visual.force.com/apex/sa_testredirect?sfdc.tabName=01r0n000000D6k3

Does anyone know what could cause this? It does not happen consistently, however I have only seen it in Chrome. The Visualforce page also ends up loading correctly if the user refreshes the page. I also haven't tested this with every Visualforce tab we have, but I suspect it's a general issue. I've been able to replicate it both with custom Visualforce pages we've developed and others from managed packages.

Thanks!
I can't figure out why my test here isn't working - I get an error message indicating my expected amount is 0 but the actual is 20. 20 is what my test should be (at the end of the code block included), so I'm not sure what's wrong.

Thanks for any help!
 
@isTest

private class Test_Line_Item_Invoice_RollupTrigger {

    static testMethod void LineItemInvoiceRollupTrigger() {
    
        {   
        
    // Create a Billing Entity record, be.
    Account be = new Account();
    be.RecordTypeId = Schema.SobjectType.Account.getRecordTypeInfosByName().get('Organization').getRecordTypeId();
    be.Name = 'Test Church';
    be.Client__c = '02CRC';
    be.Active__c = True;
    be.EFT_Active__c = True;
    be.BillingStreet = '123 Test St';
    be.BillingCity = 'Grand Rapids';
    be.BillingState = 'Michigan';
    be.BillingPostalCode = '49508';
    be.Organization_Original_Auto_Number_Value__c = '1';
    insert be;

    // Create a Participant record, p, related to be.
    Contact p = new Contact();
    p.Ultipro_ID__c = 1;
    p.FirstName = 'Stephanie';
    p.LastName = 'Arce';
    p.AccountId = be.Id;
    insert p;
    
    // Create an Invoice record, i, related to be and p.
    Invoice__c i = new Invoice__c();
    i.Invoice_Date__c = Date.NewInstance(system.today().year(), system.today().month(), 15);
    i.Billing_Entity__c = be.Id;
    i.RecordTypeId = Schema.SobjectType.Invoice__c.getRecordTypeInfosByName().get('Current Month Invoice').getRecordTypeId();
    insert i;
    
    
            // Query the Invoice to ensure Line Item Total and Line Item Total Adjusted are $0.00
            Invoice__c query1 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
            system.assertEquals(query1.Line_Item_Total__c, 0);
            system.assertEquals(query1.Line_Item_Total_Adjusted__c, 0);
            system.assertEquals(query1.Number_of_Line_Items__c, 0);

/*
------------------------------------
    Insert Test
------------------------------------
    
            // Create a Line Item record, ilicurrentinsert1, related to i and p. Inserting should cause the trigger to run.
            Line_Item__c ilicurrentinsert1 = new Line_Item__c();
            ilicurrentinsert1.Invoice__c = i.Id;
            ilicurrentinsert1.Participant__c = p.Id;
            ilicurrentinsert1.Benefit__c = 'Medical';
            ilicurrentinsert1.Plan_Option__c = 'Single HDHP - Full Time';
            ilicurrentinsert1.Ultipro_Benefit_Group__c = 'US Church';
            ilicurrentinsert1.Ultipro_Deduction_Code__c = 'MED';
            ilicurrentinsert1.Cost__c = 20;
            ilicurrentinsert1.Premium_Month__c = 'Jan';
            ilicurrentinsert1.RecordTypeId = Schema.SobjectType.Line_Item__c.getRecordTypeInfosByName().get('Existing Invoice Line Item').getRecordTypeId();
            insert ilicurrentinsert1;
    
                    // Query the Invoice to see if the amount in the Line Item was updated to Line Item Total on their record.
                    Invoice__c query2 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
                    system.assertEquals(query2.Line_Item_Total__c, 20);
                    system.assertEquals(query2.Number_of_Line_Items__c, 1);

 
Hi, I'm trying to query on 3 objects with different relationships and need some help. The "base" of my query is a Receipt object, which has a lookup to a Gift object. The Gift object then has child records in an Allocation object. What  I'd like to do is query Receipt data while listing the Allocations associated with the Gift on the receipt.

I can query the Receipt and Gift data like so:
SELECT Id, causeview__Gift__r.Id FROM causeview__Receipt__c

And query the Allocation child records from the gift:
SELECT Id, (SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c

But I'm not sure how to put the 2 together to get everything 1 query.

Thanks for any help!

I'm wondering if someone could help me bulkify this trigger. As background, we have a custom object RBA_Invoice_Line_Item__c in master-detail to RBA_Participant__c and RBA_Invoice__c. We would like to get a double amount updated on the Participant based on the Invoice Date. If it's in the current month, the total amount from the Line Items would update "Current Month Total" on the Participant. The same would happen for Line Items where the invoice date = last month, to update a "Previous Month Total" field on Participant.

 

Here is the trigger:

trigger RBA_Invoice_Line_Item_RollupTrigger on RBA_Invoice_Line_Item__c (after update, after insert, after delete) {

     Map<Id, Double> previousMonthTotals = new Map<Id, Double>();
     Map<Id, Double> currentMonthTotals = new Map<Id, Double>();
     List<RBA_Participant__c> participantsToUpdate = new List<RBA_Participant__c>();
     List<RBA_Invoice_Line_Item__c> itemsForParticipant;
     
    
     List<RBA_Invoice_Line_Item__c> items;

     if (trigger.isDelete) {
         items = trigger.old;
     }
     else {
         items = trigger.new;
     }
     
        // Go through all of the line items that the trigger
        // is acting on
        
        for (RBA_Invoice_Line_Item__c triggerItem: items) {
            
            // Get the participant's ID for the line item and then
            // ensure their ID exists in the previous / current month totals
            // maps and their totals default to $0.00
            
            Id participant = triggerItem.RBA_Participant__c;
            
            if (!previousMonthTotals.containsKey(participant)) {
                previousMonthTotals.put(participant, 0.0);
            }
            if (!currentMonthTotals.containsKey(participant)) {
                currentMonthTotals.put(participant, 0.0);
            }
            
            // Sum the total cost of all previous month's line items
            // for the current participant (see participant above)
            //
            // 1. get all of the line items for the previous month
            // 2. for each line item update the mapping for the participant 
            //    to be (previous total + total cost)
                        
            itemsForParticipant =
                [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = LAST_MONTH AND RBA_Participant__c = :participant];
            
            for (RBA_Invoice_Line_Item__c item : itemsForParticipant) {
                // previous month total = current total cost + total cost of line item
                previousMonthTotals.put(participant, 
                    previousMonthTotals.get(participant) + item.Total_Cost__c);
            }
            
            // Sum the total cost of all current month's line items
            // for the current participant (see participant above)
            //
            // 1. get all of the line items for the current month
            // 2. for each line item update the mapping for the participant 
            //    to be (previous total + total cost)
                          
            itemsForParticipant =
                [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = THIS_MONTH AND RBA_Participant__c = :participant];
            
            for (RBA_Invoice_Line_Item__c item : itemsForParticipant) {
                // current month total = current total cost + total cost of line item
                currentMonthTotals.put(participant, 
                    currentMonthTotals.get(participant) + item.Total_Cost__c);
            }
                          
        }
        
        // Collect all of the unique participant IDs from both
        // mappings into a list
        
        List<Id> participants = new List<Id>();
        
        // First add all previous month unique participants
        
        for (Id previous : previousMonthTotals.keyset()) {
            participants.add(previous);
        }
        
        // ... then add any participants in the current month totals
        // that aren't in the previous month totals
        
        for (Id current : currentMonthTotals.keyset()) {
            if (!previousMonthTotals.containsKey(current)) {
                participants .add(current);
            }
        }
        
        // For each collected participant ID from the previous step, retrieve the participant
        // record from Salesforce then update their totals if and only if we collected
        // totals from them
        
        for (Id id : participants) {
        
            RBA_Participant__c participant = [SELECT Id, Previous_Month_Total__c, Current_Month_Total__c
                 FROM RBA_Participant__c WHERE Id = :id];
                 
            if (previousMonthTotals.containsKey(id)) {
                participant.Previous_Month_Total__c = previousMonthTotals.get(id);
            }
            
            if (currentMonthTotals.containsKey(id)) {
                participant.Current_Month_Total__c = currentMonthTotals.get(id);
            }
            
            // Collect participant record in a list we will then batch update
            // once we are done looping
            
            participantsToUpdate.add(participant);
        }
        
        // Batch update all updated participants
        
        update participantsToUpdate;

}

 

I see this in the debug log:

09:22:32.982|CUMULATIVE_PROFILING|SOQL operations|
Trigger.RBA_Invoice_Line_Item_RollupTrigger: line 43, column 1: [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = LAST_MONTH AND RBA_Participant__c = :participant]: executed 51 times in 279 ms
Trigger.RBA_Invoice_Line_Item_RollupTrigger: line 60, column 1: [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = THIS_MONTH AND RBA_Participant__c = :participant]: executed 50 times in 182 ms

 

but I'm not sure how/where to move those queries?

I'm wracking my brain trying to figure out why this formula isn't working - I would like a checkbox formula field on a custom object that compares 2 date fields. One of the date fields comes from another custom object that my formula custom object has a lookup relationship to ("Church_Role_History__c").

 

Here's my formula:

NOT(ISBLANK(Church_Role_History__c)) &&
(New_End_Date__c <> Church_Role_History__r.End_Date__c)

 

I would like this checkbox to be checked if my lookup field, Church_Role_History__c is not blank, meaning my record is related to a record in that object. If it is, I'm also considering whether a date on my custom object is not equal to a date on Church_Role_History. If it's related to a Church_Role_History__c record and the dates are different, I would like the checkbox checked.

 

It's working as-is as long as there's a date entered on the Church_Role_History record (in the "End_Date__c" field, but if it's blank the checkbox is not checked. Can anyone tell me what's wrong with this formula?

Hi, I'm trying to build a trigger that acts to update a picklist with the value of another picklist (located on the same record).

 

The custom object this trigger is on needs to be restricted but we also need to let all users create and edit records here to a degree, so we have a system where they can "request an update" to the record using identical fields to the actual fields/the fields used in a report. They can fill in one picklist, but the "actual" picklist field should remain as-is until a user with additional permissions changes a checkbox from false to true. I've built everything else we need for this using workflows, but I've learned with picklists you can only go up/down the list or set it to a specific value.

 

I tried changing the picklist to a checkbox as we only have 2 possible values, but ran into the same issue where I can only set it to true or false, not the value of another checkbox. We may also add a third option so I'd like to keep this field as a picklist.

 

I have a trigger and test class written but I get an error when running my test:

System.DmlException: Update failed. First exception on row 0 with id a0DQ0000003vFohMAE; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CRHUpdateWorkStatus: execution of BeforeUpdate


caused by: System.DmlException: Update failed. First exception on row 0 with id a0DQ0000003vFohMAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0DQ0000003vFoh) is currently in trigger CRHUpdateWorkStatus, therefore it cannot recursively update itself:

 

Here is my trigger:

/* This trigger works based on if the "Request Approved" checkbox is checked.
If it is, it will update "Full-Time or Part-Time?" with the value in
"(Y) Full-Time or Part-Time?", provided that field is also not blank. */

trigger CRHUpdateWorkStatus on Church_Role_History__c (before update) {
     List<Church_Role_History__c> crhNEW = new List<Church_Role_History__c>();
     for(Church_Role_History__c crhOLD: Trigger.New)
     if (crhOLD.Request_Approved__c == True && crhOLD.Y_Full_Time_or_Part_Time__c != '')
     {
          crhNEW.add(new Church_Role_History__c (
          
          // Id
          id = crhOLD.Id,
          
          // Status
          Full_Time_or_Part_Time__c = crhOLD.Y_Full_Time_or_Part_Time__c
          ));
     }
     update crhNEW;
}

 

 

My test class:

@isTest
     private class TESTCRHUpdateWorkStatus {
          public static testmethod void MyTest() {
     
     {
          
          //Create a Contact for this test class.
          Contact c = new Contact();
          c.FirstName = 'Stephanie';
          c.LastName = 'Arce';
          insert c;
          
          //Create an Account for this test class.
          Account a = new Account();
          a.Name = 'Test Church';
          insert a;
     
          //insert a Church Role History record related to the Contact and Account.
          Church_Role_History__c crh = new Church_Role_History__c ();
          crh.Church__c = a.Id;
          crh.Person__c = c.Id;
          crh.Y_Full_Time_or_Part_Time__c = 'Full-Time';
          crh.Church_Position_Title__c = 'Administrative Assistant';
          crh.Request_Approved__c = True;
          insert crh;
          
          //Update the same Church Role History record so Request Approved = True.
          Church_Role_History__c crhu = [select Id from Church_Role_History__c where Id = :crh.Id];
          crhu.Request_Approved__c = True;
          update crhu;
          //See if "(Y) Full-Time or Part-Time?" value was copied to "Full-Time or Part-Time?"
          Church_Role_History__c crhq = [select Id from Church_Role_History__c where Id = :crhu.Id];
          system.assertEquals(crhq.Full_Time_or_Part_Time__c, 'Full-Time');
     }
   }
 }

 

Can someone explain the error message to me and what I have wrong in my trigger? Thank you so much for any help!

Hi, I was wondering if someone could help me with an Apex trigger I'm trying to write? I am completely new to coding, please bear with me -

 

I am working with a custom object and Accounts. In the custom object, when a checkbox = true, values in that record should update the corresponding Account's fields. Every record in this custom object is related to an Account so I tried at first creating a master-detail relationship and then using SF's workflows, but we will also need to see history on these custom object records (particularly which of our users checked the checkbox), which I've read you can't get using master-detail relationships so it's a lookup currently.

 

This is what I have so far - a record in this custom object will never have the checkbox ("Approved__c") selected upon insert, only upon update:

 

trigger CQApprovedUpsertChurch on Church_Questionnaire__c (before update) {
    List<Account> a = new List<Account> ();
    for (Church_Questionnaire__c ApprovedCQ: Trigger.New)
    if (ApprovedCQ.Approved__c = True)
        {
            a.add (new Account (
            CORE_Yearbook_ID__c = ApprovedCQ.Church_Yearbook_ID__c,
            Mailing_Street_1__c = ApprovedCQ.Mailing_Street_1__c,
            Mailing_Street_2__c = ApprovedCQ.Mailing_Street_2__c,
            Mailing_Street_3__c = ApprovedCQ.Mailing_Street_3__c,
            Mailing_City__c = ApprovedCQ.Mailing_City__c,
            Mailing_State_Province__c = ApprovedCQ.Mailing_State_Province__c,
            Mailing_Zip_Postal_Code__c = ApprovedCQ.Mailing_Zip_Postal_Code__c
            ));
        }
    upsert a Account.CORE_Yearbook_ID__c;
}

 

It is working to update the Account's address when the custom object record is saved and Approved__c = True, however when I edit that same record to uncheck Approved__c and save, it becomes checked again.

 

I tried changing my "before update" statement to "before insert, before update", and when that's in place, if I insert a record Approved__c is checked regardless of whether I actually checked it or not.

 

Can someone tell me what I'm doing wrong/what's wrong with my logic?

Hi, I'm trying to query on 3 objects with different relationships and need some help. The "base" of my query is a Receipt object, which has a lookup to a Gift object. The Gift object then has child records in an Allocation object. What  I'd like to do is query Receipt data while listing the Allocations associated with the Gift on the receipt.

I can query the Receipt and Gift data like so:
SELECT Id, causeview__Gift__r.Id FROM causeview__Receipt__c

And query the Allocation child records from the gift:
SELECT Id, (SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c

But I'm not sure how to put the 2 together to get everything 1 query.

Thanks for any help!
We have a Visualforce tab that users go to and occassionally get "stuck" on at a URL similar to this:

https://cs67.salesforce.com/servlet/servlet.Integration?lid=01r0n000000D6k3&ic=1&linkToken=VmpFPSxNakF4T0Mwd09DMHhNMVF5TURveE5Eb3pNUzR5TnpsYSx3YmJfXzV3ZnVOREVtdXlTcm9ldWFwLFlXWmtNR0po

The Visualforce page ends up not loading. Normally, they'll see this URL for just a second and then get directed to the Visualforce page, for example: https://c.cs67.visual.force.com/apex/sa_testredirect?sfdc.tabName=01r0n000000D6k3

Does anyone know what could cause this? It does not happen consistently, however I have only seen it in Chrome. The Visualforce page also ends up loading correctly if the user refreshes the page. I also haven't tested this with every Visualforce tab we have, but I suspect it's a general issue. I've been able to replicate it both with custom Visualforce pages we've developed and others from managed packages.

Thanks!
I can't figure out why my test here isn't working - I get an error message indicating my expected amount is 0 but the actual is 20. 20 is what my test should be (at the end of the code block included), so I'm not sure what's wrong.

Thanks for any help!
 
@isTest

private class Test_Line_Item_Invoice_RollupTrigger {

    static testMethod void LineItemInvoiceRollupTrigger() {
    
        {   
        
    // Create a Billing Entity record, be.
    Account be = new Account();
    be.RecordTypeId = Schema.SobjectType.Account.getRecordTypeInfosByName().get('Organization').getRecordTypeId();
    be.Name = 'Test Church';
    be.Client__c = '02CRC';
    be.Active__c = True;
    be.EFT_Active__c = True;
    be.BillingStreet = '123 Test St';
    be.BillingCity = 'Grand Rapids';
    be.BillingState = 'Michigan';
    be.BillingPostalCode = '49508';
    be.Organization_Original_Auto_Number_Value__c = '1';
    insert be;

    // Create a Participant record, p, related to be.
    Contact p = new Contact();
    p.Ultipro_ID__c = 1;
    p.FirstName = 'Stephanie';
    p.LastName = 'Arce';
    p.AccountId = be.Id;
    insert p;
    
    // Create an Invoice record, i, related to be and p.
    Invoice__c i = new Invoice__c();
    i.Invoice_Date__c = Date.NewInstance(system.today().year(), system.today().month(), 15);
    i.Billing_Entity__c = be.Id;
    i.RecordTypeId = Schema.SobjectType.Invoice__c.getRecordTypeInfosByName().get('Current Month Invoice').getRecordTypeId();
    insert i;
    
    
            // Query the Invoice to ensure Line Item Total and Line Item Total Adjusted are $0.00
            Invoice__c query1 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
            system.assertEquals(query1.Line_Item_Total__c, 0);
            system.assertEquals(query1.Line_Item_Total_Adjusted__c, 0);
            system.assertEquals(query1.Number_of_Line_Items__c, 0);

/*
------------------------------------
    Insert Test
------------------------------------
    
            // Create a Line Item record, ilicurrentinsert1, related to i and p. Inserting should cause the trigger to run.
            Line_Item__c ilicurrentinsert1 = new Line_Item__c();
            ilicurrentinsert1.Invoice__c = i.Id;
            ilicurrentinsert1.Participant__c = p.Id;
            ilicurrentinsert1.Benefit__c = 'Medical';
            ilicurrentinsert1.Plan_Option__c = 'Single HDHP - Full Time';
            ilicurrentinsert1.Ultipro_Benefit_Group__c = 'US Church';
            ilicurrentinsert1.Ultipro_Deduction_Code__c = 'MED';
            ilicurrentinsert1.Cost__c = 20;
            ilicurrentinsert1.Premium_Month__c = 'Jan';
            ilicurrentinsert1.RecordTypeId = Schema.SobjectType.Line_Item__c.getRecordTypeInfosByName().get('Existing Invoice Line Item').getRecordTypeId();
            insert ilicurrentinsert1;
    
                    // Query the Invoice to see if the amount in the Line Item was updated to Line Item Total on their record.
                    Invoice__c query2 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
                    system.assertEquals(query2.Line_Item_Total__c, 20);
                    system.assertEquals(query2.Number_of_Line_Items__c, 1);

 
Hi, I'm trying to query on 3 objects with different relationships and need some help. The "base" of my query is a Receipt object, which has a lookup to a Gift object. The Gift object then has child records in an Allocation object. What  I'd like to do is query Receipt data while listing the Allocations associated with the Gift on the receipt.

I can query the Receipt and Gift data like so:
SELECT Id, causeview__Gift__r.Id FROM causeview__Receipt__c

And query the Allocation child records from the gift:
SELECT Id, (SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c

But I'm not sure how to put the 2 together to get everything 1 query.

Thanks for any help!

Hi,

 

I am trying to create Workflow rule where Target Date greater than Today()

 

but it is giving me an error  Error: Invalid date (Valid date format 11/14/2013)

 

Target Date is the field with Date Type.

 

Can anyone tell me how to resolve this error

 

 

I'm wondering if someone could help me bulkify this trigger. As background, we have a custom object RBA_Invoice_Line_Item__c in master-detail to RBA_Participant__c and RBA_Invoice__c. We would like to get a double amount updated on the Participant based on the Invoice Date. If it's in the current month, the total amount from the Line Items would update "Current Month Total" on the Participant. The same would happen for Line Items where the invoice date = last month, to update a "Previous Month Total" field on Participant.

 

Here is the trigger:

trigger RBA_Invoice_Line_Item_RollupTrigger on RBA_Invoice_Line_Item__c (after update, after insert, after delete) {

     Map<Id, Double> previousMonthTotals = new Map<Id, Double>();
     Map<Id, Double> currentMonthTotals = new Map<Id, Double>();
     List<RBA_Participant__c> participantsToUpdate = new List<RBA_Participant__c>();
     List<RBA_Invoice_Line_Item__c> itemsForParticipant;
     
    
     List<RBA_Invoice_Line_Item__c> items;

     if (trigger.isDelete) {
         items = trigger.old;
     }
     else {
         items = trigger.new;
     }
     
        // Go through all of the line items that the trigger
        // is acting on
        
        for (RBA_Invoice_Line_Item__c triggerItem: items) {
            
            // Get the participant's ID for the line item and then
            // ensure their ID exists in the previous / current month totals
            // maps and their totals default to $0.00
            
            Id participant = triggerItem.RBA_Participant__c;
            
            if (!previousMonthTotals.containsKey(participant)) {
                previousMonthTotals.put(participant, 0.0);
            }
            if (!currentMonthTotals.containsKey(participant)) {
                currentMonthTotals.put(participant, 0.0);
            }
            
            // Sum the total cost of all previous month's line items
            // for the current participant (see participant above)
            //
            // 1. get all of the line items for the previous month
            // 2. for each line item update the mapping for the participant 
            //    to be (previous total + total cost)
                        
            itemsForParticipant =
                [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = LAST_MONTH AND RBA_Participant__c = :participant];
            
            for (RBA_Invoice_Line_Item__c item : itemsForParticipant) {
                // previous month total = current total cost + total cost of line item
                previousMonthTotals.put(participant, 
                    previousMonthTotals.get(participant) + item.Total_Cost__c);
            }
            
            // Sum the total cost of all current month's line items
            // for the current participant (see participant above)
            //
            // 1. get all of the line items for the current month
            // 2. for each line item update the mapping for the participant 
            //    to be (previous total + total cost)
                          
            itemsForParticipant =
                [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = THIS_MONTH AND RBA_Participant__c = :participant];
            
            for (RBA_Invoice_Line_Item__c item : itemsForParticipant) {
                // current month total = current total cost + total cost of line item
                currentMonthTotals.put(participant, 
                    currentMonthTotals.get(participant) + item.Total_Cost__c);
            }
                          
        }
        
        // Collect all of the unique participant IDs from both
        // mappings into a list
        
        List<Id> participants = new List<Id>();
        
        // First add all previous month unique participants
        
        for (Id previous : previousMonthTotals.keyset()) {
            participants.add(previous);
        }
        
        // ... then add any participants in the current month totals
        // that aren't in the previous month totals
        
        for (Id current : currentMonthTotals.keyset()) {
            if (!previousMonthTotals.containsKey(current)) {
                participants .add(current);
            }
        }
        
        // For each collected participant ID from the previous step, retrieve the participant
        // record from Salesforce then update their totals if and only if we collected
        // totals from them
        
        for (Id id : participants) {
        
            RBA_Participant__c participant = [SELECT Id, Previous_Month_Total__c, Current_Month_Total__c
                 FROM RBA_Participant__c WHERE Id = :id];
                 
            if (previousMonthTotals.containsKey(id)) {
                participant.Previous_Month_Total__c = previousMonthTotals.get(id);
            }
            
            if (currentMonthTotals.containsKey(id)) {
                participant.Current_Month_Total__c = currentMonthTotals.get(id);
            }
            
            // Collect participant record in a list we will then batch update
            // once we are done looping
            
            participantsToUpdate.add(participant);
        }
        
        // Batch update all updated participants
        
        update participantsToUpdate;

}

 

I see this in the debug log:

09:22:32.982|CUMULATIVE_PROFILING|SOQL operations|
Trigger.RBA_Invoice_Line_Item_RollupTrigger: line 43, column 1: [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = LAST_MONTH AND RBA_Participant__c = :participant]: executed 51 times in 279 ms
Trigger.RBA_Invoice_Line_Item_RollupTrigger: line 60, column 1: [SELECT Id, Total_Cost__c FROM RBA_Invoice_Line_Item__c
                    WHERE Invoice_Date__c = THIS_MONTH AND RBA_Participant__c = :participant]: executed 50 times in 182 ms

 

but I'm not sure how/where to move those queries?

Hi everyone,

Can you please help me to write a test class for below code:

 

public class retrieveOpenSiteDefects    {     
      private ApexPages.StandardSetController controller;                                   
      public List<Site_Defects__c> getOutbaseSiteDefects()                
       {                          
             return [SELECT Id, Name, Date_Raised__c,Contractor__c,Defect_Type__c,Status__c         
             FROM Site_Defects__c WHERE Status__c = 'Open' order by Date_Raised__c desc limit 10];           
        }
}

 I have been trying by this:

 

@isTest
public class testRetrieveOpenIncidents{

    static testMethod void testOpenIncident(){
        Incident__c i = new Incident__c(Name='test',Current_Owner__c= 'me',  Date_Occurred__c= 2013-11-12,
                                        Description__c= 'none', Due_Date__c= 2013-11-25,
                                        Open_Actions__c= 'Investigate,',
                                        RCA_Approved__c='Y',
                                        RCA_Submission_Date__c= 2013-11-12,
                                        Status__c= 'Under Investigation',
                                        Terminal__c= 'Test'
                                        Transport_Contractor__c= 'salesforce test'
                                        )
    
    
    
    }

 

for some reason it does not like date :/

 

Thanks

 

 

I'm wracking my brain trying to figure out why this formula isn't working - I would like a checkbox formula field on a custom object that compares 2 date fields. One of the date fields comes from another custom object that my formula custom object has a lookup relationship to ("Church_Role_History__c").

 

Here's my formula:

NOT(ISBLANK(Church_Role_History__c)) &&
(New_End_Date__c <> Church_Role_History__r.End_Date__c)

 

I would like this checkbox to be checked if my lookup field, Church_Role_History__c is not blank, meaning my record is related to a record in that object. If it is, I'm also considering whether a date on my custom object is not equal to a date on Church_Role_History. If it's related to a Church_Role_History__c record and the dates are different, I would like the checkbox checked.

 

It's working as-is as long as there's a date entered on the Church_Role_History record (in the "End_Date__c" field, but if it's blank the checkbox is not checked. Can anyone tell me what's wrong with this formula?

Hi, I'm trying to build a trigger that acts to update a picklist with the value of another picklist (located on the same record).

 

The custom object this trigger is on needs to be restricted but we also need to let all users create and edit records here to a degree, so we have a system where they can "request an update" to the record using identical fields to the actual fields/the fields used in a report. They can fill in one picklist, but the "actual" picklist field should remain as-is until a user with additional permissions changes a checkbox from false to true. I've built everything else we need for this using workflows, but I've learned with picklists you can only go up/down the list or set it to a specific value.

 

I tried changing the picklist to a checkbox as we only have 2 possible values, but ran into the same issue where I can only set it to true or false, not the value of another checkbox. We may also add a third option so I'd like to keep this field as a picklist.

 

I have a trigger and test class written but I get an error when running my test:

System.DmlException: Update failed. First exception on row 0 with id a0DQ0000003vFohMAE; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CRHUpdateWorkStatus: execution of BeforeUpdate


caused by: System.DmlException: Update failed. First exception on row 0 with id a0DQ0000003vFohMAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0DQ0000003vFoh) is currently in trigger CRHUpdateWorkStatus, therefore it cannot recursively update itself:

 

Here is my trigger:

/* This trigger works based on if the "Request Approved" checkbox is checked.
If it is, it will update "Full-Time or Part-Time?" with the value in
"(Y) Full-Time or Part-Time?", provided that field is also not blank. */

trigger CRHUpdateWorkStatus on Church_Role_History__c (before update) {
     List<Church_Role_History__c> crhNEW = new List<Church_Role_History__c>();
     for(Church_Role_History__c crhOLD: Trigger.New)
     if (crhOLD.Request_Approved__c == True && crhOLD.Y_Full_Time_or_Part_Time__c != '')
     {
          crhNEW.add(new Church_Role_History__c (
          
          // Id
          id = crhOLD.Id,
          
          // Status
          Full_Time_or_Part_Time__c = crhOLD.Y_Full_Time_or_Part_Time__c
          ));
     }
     update crhNEW;
}

 

 

My test class:

@isTest
     private class TESTCRHUpdateWorkStatus {
          public static testmethod void MyTest() {
     
     {
          
          //Create a Contact for this test class.
          Contact c = new Contact();
          c.FirstName = 'Stephanie';
          c.LastName = 'Arce';
          insert c;
          
          //Create an Account for this test class.
          Account a = new Account();
          a.Name = 'Test Church';
          insert a;
     
          //insert a Church Role History record related to the Contact and Account.
          Church_Role_History__c crh = new Church_Role_History__c ();
          crh.Church__c = a.Id;
          crh.Person__c = c.Id;
          crh.Y_Full_Time_or_Part_Time__c = 'Full-Time';
          crh.Church_Position_Title__c = 'Administrative Assistant';
          crh.Request_Approved__c = True;
          insert crh;
          
          //Update the same Church Role History record so Request Approved = True.
          Church_Role_History__c crhu = [select Id from Church_Role_History__c where Id = :crh.Id];
          crhu.Request_Approved__c = True;
          update crhu;
          //See if "(Y) Full-Time or Part-Time?" value was copied to "Full-Time or Part-Time?"
          Church_Role_History__c crhq = [select Id from Church_Role_History__c where Id = :crhu.Id];
          system.assertEquals(crhq.Full_Time_or_Part_Time__c, 'Full-Time');
     }
   }
 }

 

Can someone explain the error message to me and what I have wrong in my trigger? Thank you so much for any help!

Hi, I was wondering if someone could help me with an Apex trigger I'm trying to write? I am completely new to coding, please bear with me -

 

I am working with a custom object and Accounts. In the custom object, when a checkbox = true, values in that record should update the corresponding Account's fields. Every record in this custom object is related to an Account so I tried at first creating a master-detail relationship and then using SF's workflows, but we will also need to see history on these custom object records (particularly which of our users checked the checkbox), which I've read you can't get using master-detail relationships so it's a lookup currently.

 

This is what I have so far - a record in this custom object will never have the checkbox ("Approved__c") selected upon insert, only upon update:

 

trigger CQApprovedUpsertChurch on Church_Questionnaire__c (before update) {
    List<Account> a = new List<Account> ();
    for (Church_Questionnaire__c ApprovedCQ: Trigger.New)
    if (ApprovedCQ.Approved__c = True)
        {
            a.add (new Account (
            CORE_Yearbook_ID__c = ApprovedCQ.Church_Yearbook_ID__c,
            Mailing_Street_1__c = ApprovedCQ.Mailing_Street_1__c,
            Mailing_Street_2__c = ApprovedCQ.Mailing_Street_2__c,
            Mailing_Street_3__c = ApprovedCQ.Mailing_Street_3__c,
            Mailing_City__c = ApprovedCQ.Mailing_City__c,
            Mailing_State_Province__c = ApprovedCQ.Mailing_State_Province__c,
            Mailing_Zip_Postal_Code__c = ApprovedCQ.Mailing_Zip_Postal_Code__c
            ));
        }
    upsert a Account.CORE_Yearbook_ID__c;
}

 

It is working to update the Account's address when the custom object record is saved and Approved__c = True, however when I edit that same record to uncheck Approved__c and save, it becomes checked again.

 

I tried changing my "before update" statement to "before insert, before update", and when that's in place, if I insert a record Approved__c is checked regardless of whether I actually checked it or not.

 

Can someone tell me what I'm doing wrong/what's wrong with my logic?