• Austin Gutz
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Salesforce Admin
  • Echo Engineering & Supply

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 12
    Replies
I found a formula on the community to use to calculate the buiness hours between two date.

The formula works perfect... unless the created date is before our business hours.
*Business hours: 8am-5pm EST(M-F)

User-added image
 
IF( 

(((Assigned_Time__c - CreatedDate)*1440) / 60) < 0.1, 0, 

9 *( (5*FLOOR((DATEVALUE(IF(ISNULL(Assigned_Time__c), Assigned_Time__c, Assigned_Time__c)) - DATE(1996,01,01))/7) 
+ 
MIN(5, 
MOD(DATEVALUE(IF(ISNULL(Assigned_Time__c), Assigned_Time__c, Assigned_Time__c)) - DATE(1996,01,01), 7) + 
MIN(1, 24/ 9 *(MOD(IF(ISNULL(Assigned_Time__c), Assigned_Time__c, Assigned_Time__c) - DATETIMEVALUE('1996-01-01 14:00:00'), 1))) 
)) 

- 

(5*FLOOR((DATEVALUE(CreatedDate + MAX(DATETIMEVALUE(TEXT(DATEVALUE(CreatedDate)) & " 14:00:00") - CreatedDate,0)) - DATE(1996,01,01))/7) + 
MIN(5, 
MOD(DATEVALUE(CreatedDate + MAX(DATETIMEVALUE(TEXT(DATEVALUE(CreatedDate)) & " 14:00:00") - CreatedDate ,0)) - DATE(1996,01,01), 7) + 
MIN(1, 24/ 9 *(MOD(CreatedDate + MAX(DATETIMEVALUE(TEXT(DATEVALUE(CreatedDate)) & " 14:00:00") - CreatedDate ,0) - DATETIMEVALUE('1996-01-01 14:00:00'), 1))))) 
) 
)

 
Our accounting controller would like to assign tasks to different users for any account that's past due. 

Basically, every Monday I need tasks auto-generated for any account where past_due_amount__c > $0. The task would be auto assigned to the user in the collections_owner__c field found on the account with a due date of the end of the week. 

If Apex, can someone help me with that?
Anyone have a better idea? 

Here is what I have so far.
global class WeeklyAccountingTasks implements schedule{
    global void execute(schedulableContext ctx){
        List<account> Accts = [SELECT Id, Name, Collection_Ownership__c, Past_Due_Amount__c
            FROM Account
            WHERE Past_Due_Amount__c > 0];
        // Create a task for each account in the list
    }

}

 
Hi All,

We have a button on a record page that executes JavaScript. This triggers an integration that synces the record information to our ERP. Anytime a user makes an edit on the record they are supposed to click that button... that isn't alays happening.

I'm looking for a way to take the human eliment out of the button click. Is there a way to use process builder or workflow to click the button if the record it edited? 

Here is the JavaScript
{!REQUIRESCRIPT("/soap/ajax/12.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/12.0/apex.js")}
{!REQUIRESCRIPT("/support/console/10.0/integration.js")}
alert(sforce.apex.execute("CC_WebServices","promoteToShip",{ship:"{!Shipping_Address__c.Id}"}));

 
I have a class that compares two fields on an Object and forces an update to trigger a process builder if the fields are a mismatch.

The code works just fine if I run it in the Dev Console.
List<Open_AR_Doc__c> lstINVToUpdate = new List<Open_AR_Doc__c>();
        List<Open_AR_Doc__c> lList = [Select Id, Name, Invoice_Standing__c ,Invoice_Standing_Text__c from Open_AR_Doc__c];
        for(Open_AR_Doc__c inv : lList){
            if(inv.recordTypeId == '0125A000001NaOj' && inv.Invoice_Standing_Text__c != inv.Invoice_Standing__c){
                lstINVToUpdate.add(inv);
            }
        }
        
        if(lstINVToUpdate.size() > 0){
            update lstINVToUpdate;
        }
But when I schedule the class it runs but doesn't actually update the reocrds. 
global class DailyOpenARDocInvoiceUpdate implements Schedulable {

    global void execute(SchedulableContext ctx) {
    
        List<Open_AR_Doc__c> lstINVToUpdate = new List<Open_AR_Doc__c>();
        List<Open_AR_Doc__c> lList = [Select Id, Name, Invoice_Standing__c ,Invoice_Standing_Text__c from Open_AR_Doc__c];
        for(Open_AR_Doc__c inv : lList){
            if(inv.recordTypeId == '0125A000001NaOj' && inv.Invoice_Standing_Text__c != inv.Invoice_Standing__c){
                lstINVToUpdate.add(inv);
            }
        }
        
        if(lstINVToUpdate.size() > 0){
            update lstINVToUpdate;
        }
    }
}


 
trigger UpdateOppEmail on OpportunityTeamMember (after insert) {

    List<OpportunityTeamMember> memberList = new List<OpportunityTeamMember>();
    List<Opportunity> oppToUpdateList = new List<Opportunity>();
    List<Id> idUserList = new List<Id>();
    
    for(OpportunityTeamMember member : trigger.new) {
        
        if(member.TeamMemberRole != 'Program Manager') continue;
        
        memberList.add(member);
        idUserList.add(member.UserId);
    }
    
    if(memberList.isEmpty()) return;
    
    Map<Id, User> userMap = new Map<Id, User>([SELECT Id, Email FROM User WHERE Id IN :idUserList]);
    
    for(OpportunityTeamMember member : memberList) {
        
        Opportunity oppToUpdate = new Opportunity(Id = member.OpportunityId);
        oppToUpdate.PM_Email__c = userMap.get(member.UserId).Email;
        
        oppToUpdateList.add(oppToUpdate);
    }

    update oppToUpdateList;
}
Can anyone help me start writing a test class for this Trigger? I'm not a developer so I really don't have any APEX experience. I think I understand the idea is to create a test record(s) to cause the trigger to go off thus testing its functionality... I just don't know how to start writing that. Any help would be greatly appreciated. 
 
I've found a few posts that kind of address this need but I can't seem to get any of them to work.

I feel like I'm kind of close with this post: https://developer.salesforce.com/forums/?id=906F00000005KqHIAU

I need to trigger an email send from a custom object related to an Opportunity. The email needs to go to the Opportunity Team member with the role of Program Manager. I've added a custom email field on the Opportunity called PM_Email__c and had hoped I could update this field with process builder or a workflow rule... turns out that's not an option. I'd use this field to populate another email field on my custom object but I need to first find a way to get the email in the Opportunity field. Any help? 
I found a very basic Apex class to update a custom object and have it scheduled to run nightly. It was working just fine for a few days but now I'm getting a CPU time limit error.

Would it help to only list the records that need updating? If yes, what do I need to modify in the class to do so?

I'd like to only update records were Field1__c != Field__c2
global class DailyOpenInvoiceUpdate implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Open_Invoices__c> lList = [Select Id, Name from Open_Invoices__c];
        
      update lList;
    
    }
}

 
I'm trying to deploy a very simple Apex class that I'll then schedule to do a nightly record update. The deployment is failing because of errors with a test class that came from an installed app. I'm an admin, so I have very little Apex knowledge.

The errors are all:
System.QueryException: List has no rows for assignment to SObject 

All the errors point to a line with:   User u = getUser('NotAccessible1');

From what I'm reading it has something to do with an empty query. I just don't know how to fix it. I'll post the code in a different comment. 
I'm trying to build a formula (boolean) that's checked "TRUE" if the Close Date on the record was for LAST WEEK. 
I have found some posts about how to query for line item values but I can't seem to find out how to format the query based on line item values. 

Example:

SELECT Name, (Select PricebookEntry.Product2Id,Certainty_Percentage__c, TotalPrice, From OpportunityLineItems) 

From Opportunity

WHERE 
 
Certainty_Percentage__c = '90%'   

The problem is I want the certain percentage value on the line item, not the opportunity itself. I tried just doing "From OpportunityLineItems" but I get an error every time. 
I have the following query:
SELECT 
Completed_Date__c, CreatedDate, Description, Subject__c, Account.Name, Account.Status__c,CreatedBy.Name, Owner.Name
FROM Task 
WHERE
Completed_Date__c = LAST_WEEK 
AND
(
Subject__c LIKE '%Customer%' OR
Subject__c LIKE '%Lead%'
)
AND
Owner.Name = 'Employee Name'
This query pulls all tasks associated with Owner.Name = 'Insert Employee Name'. I'm then using the result to populate a Conga Word table that displays the task Subject. The problem is the results look like this:

Customer - Meeting
Customer - Meeting
Customer - Email
Lead - Contact
Lead - Contact
Lead - Contact

I'm trying to find a way to group and count the results. So something like this

Customer - Meeting 2
Customer - Email 1
Lead - Contact 3

Normally I could achieve this using a summary report and pull that information into the Conga template but the users running the merge don't have access to export reports so I have to use queries. 
Our accounting controller would like to assign tasks to different users for any account that's past due. 

Basically, every Monday I need tasks auto-generated for any account where past_due_amount__c > $0. The task would be auto assigned to the user in the collections_owner__c field found on the account with a due date of the end of the week. 

If Apex, can someone help me with that?
Anyone have a better idea? 

Here is what I have so far.
global class WeeklyAccountingTasks implements schedule{
    global void execute(schedulableContext ctx){
        List<account> Accts = [SELECT Id, Name, Collection_Ownership__c, Past_Due_Amount__c
            FROM Account
            WHERE Past_Due_Amount__c > 0];
        // Create a task for each account in the list
    }

}

 
I've found a few posts that kind of address this need but I can't seem to get any of them to work.

I feel like I'm kind of close with this post: https://developer.salesforce.com/forums/?id=906F00000005KqHIAU

I need to trigger an email send from a custom object related to an Opportunity. The email needs to go to the Opportunity Team member with the role of Program Manager. I've added a custom email field on the Opportunity called PM_Email__c and had hoped I could update this field with process builder or a workflow rule... turns out that's not an option. I'd use this field to populate another email field on my custom object but I need to first find a way to get the email in the Opportunity field. Any help? 
I found a very basic Apex class to update a custom object and have it scheduled to run nightly. It was working just fine for a few days but now I'm getting a CPU time limit error.

Would it help to only list the records that need updating? If yes, what do I need to modify in the class to do so?

I'd like to only update records were Field1__c != Field__c2
global class DailyOpenInvoiceUpdate implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Open_Invoices__c> lList = [Select Id, Name from Open_Invoices__c];
        
      update lList;
    
    }
}

 
I'm trying to deploy a very simple Apex class that I'll then schedule to do a nightly record update. The deployment is failing because of errors with a test class that came from an installed app. I'm an admin, so I have very little Apex knowledge.

The errors are all:
System.QueryException: List has no rows for assignment to SObject 

All the errors point to a line with:   User u = getUser('NotAccessible1');

From what I'm reading it has something to do with an empty query. I just don't know how to fix it. I'll post the code in a different comment. 
I'm trying to build a formula (boolean) that's checked "TRUE" if the Close Date on the record was for LAST WEEK. 
I have found some posts about how to query for line item values but I can't seem to find out how to format the query based on line item values. 

Example:

SELECT Name, (Select PricebookEntry.Product2Id,Certainty_Percentage__c, TotalPrice, From OpportunityLineItems) 

From Opportunity

WHERE 
 
Certainty_Percentage__c = '90%'   

The problem is I want the certain percentage value on the line item, not the opportunity itself. I tried just doing "From OpportunityLineItems" but I get an error every time. 
I have the following query:
SELECT 
Completed_Date__c, CreatedDate, Description, Subject__c, Account.Name, Account.Status__c,CreatedBy.Name, Owner.Name
FROM Task 
WHERE
Completed_Date__c = LAST_WEEK 
AND
(
Subject__c LIKE '%Customer%' OR
Subject__c LIKE '%Lead%'
)
AND
Owner.Name = 'Employee Name'
This query pulls all tasks associated with Owner.Name = 'Insert Employee Name'. I'm then using the result to populate a Conga Word table that displays the task Subject. The problem is the results look like this:

Customer - Meeting
Customer - Meeting
Customer - Email
Lead - Contact
Lead - Contact
Lead - Contact

I'm trying to find a way to group and count the results. So something like this

Customer - Meeting 2
Customer - Email 1
Lead - Contact 3

Normally I could achieve this using a summary report and pull that information into the Conga template but the users running the merge don't have access to export reports so I have to use queries.