• MattMet86
  • NEWBIE
  • 155 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 65
    Questions
  • 83
    Replies
I have a visualforce page passing a value to controller.
Variable name is stFilter
My soql is:
Select Id, Name, User__r.Name, 
(Select Id,Account__c,Account__r.Name,Hub_Name__r.Name FROM Account_Counselors__r), 
(Select Name FROM Licenses__r) 
FROM BCS__c WHERE Inactive__C = FALSE
How do I filter it so that only BCS_c records that have a Licenses__r record with "Name" value matching stFilter are returned.

Example
stfilter = Kansas
I only want to get back BCS__c records that have a Licenses__r record for Kansas.
Need a little help. I can't figure out the correct syntax to utilize Task What.Type in my trigger. Can someone tell me what I am doing wrong?
 
trigger ININRelatedToFix on Task (after Insert, after Update) {
    
    //Get Record Type    
    RecordType Five9Rec = [select id from RecordType where name = 'Five9 Call' AND sobjecttype = 'Task' limit 1];
    system.debug('RecordType= '+Five9Rec.Id);
    
    //Create List for bulkified update
    List<Task> taskList = new List<Task>();
    
    //Loop through each task handed to trigger
    for (Task T : Trigger.new) {
        
        //If Call is related to Employee Session instead of Employee
        //*******************
        If(T.What.Type.equals('Employee_Session__c') && T.RecordTypeId == Five9Rec.Id){
            
            //Get the employee
            Employee_Session__c Emp = [Select Employee__c FROM Employee_Session__c WHERE ID = :T.WhatId];
            
            //Fix Relationship
            T.WhatId = Emp.Employee__c;
            taskList.add(t);
        }
    }
    
    //Builify Update
    update tasklist;
}

 
Ok, I have the following schedulable class but I am running into the SOQL limit on my query. The query should return back around 60 summaires at most but one of our accounts has 92,000 employees which is where i think I am hitting the limit. Can anyone help me code this to get past the limit? 

I put a comment around the soql block that is breaking. 
global class BCI_Account_State_Count_Rollup implements Schedulable {
/*
Created by MM - 1/25/2016
Purpose - count the state field for each active employee on 
an account and update the corresponding state field count
on the account page. 
*/

//Used for aggregrateresults
Public Summary[] Summaries { get; set; }

//Make class schedulable    
global void execute(SchedulableContext ctx) {        
    CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime
                      FROM CronTrigger WHERE Id = :ctx.getTriggerId()];


    //Create Set with fields from Account page.
    Set<String> statesAcct = new Set<string>{
        'AL','AK','AZ','AR','CA','CO',
            'CT','DE','FL','GA','HI','ID',
            'IL','IN','IA','KS','KY','LA',
            'ME','MD','MA','MI','MN','MS',
            'MO','MT','NE','NV','NH','NJ',
            'NM','NY','NC','ND','OH','OK',
            'OR','PA','RI','SC','SD','TN',
            'TX','UT','VT','VA','WA','WV',
            'WI','WY',
            //Commonwealth/Territories
            'DC'};


                //Create List of active accounts
                list<account> myAccounts = new list<account>();
    myAccounts = [Select ID, Name from Account WHERE Type = 'Client'];

    //Create list to bulkify update command at end of loop
    list<account> accountsToUpdate = new list<account>();

    //Get active employee counts for every account.
    //Getting all at once to limit SOQL queries. 
    Summaries = new List<Summary>();

//CODE THAT IS BREAKING DUE TO SOQL LIMIT
        AggregateResult[] groupedResults = [SELECT COUNT(ID) ct, State__c st, Account__c acct FROM Employees__c WHERE Type__c = 'Client' AND Inactive__c != 'X' GROUP BY Account__c,State__c];
//END BROKEN CODE

    for (AggregateResult ar : groupedResults) {
        Summaries.add(new Summary(ar));
    }


    //Loop MyAccounts
    for ( Account a : myAccounts ){

        //Create map of specific account aggregrate results per state. 
        Map<String, integer> aggregateAcct = new Map<String, integer>();


        //Loop - extract aggregrateResult data just for current account. 
        for(Summary s : Summaries ){
            //system.debug('Summary' + s.acctid);
            //system.debug('Account' + a.Id);

            if(s.acctId == a.id){
                aggregateAcct.put(s.stateName,s.stateCount);
                //System.debug('aggregateAcct - ' + s.stateName + '-' + s.stateCount); 
            } 
        }
        //End Loop - Summaries

        //Create State Name to State count field Map
        Map<String, integer> stateCount = new Map<String, integer>();

        //Link the state count to the field name that is used on the Account object 
        //This way we only get values for states that we have fields for on Account object.
        for(String st : statesAcct){
            StateCount.Put(st, aggregateAcct.get(st));  
        }

        //Now update each state field using our stored values. 
        //Values in StateCount map are now StateAbbreviation and Count

        a.AK__c = stateCount.get('AK');
        a.AL__c = stateCount.get('AL');
        a.AR__c = stateCount.get('AR');
        a.AZ__c = stateCount.get('AZ');
        a.CA__c = stateCount.get('CA');
        a.CO__c = stateCount.get('CO');
        a.CT__c = stateCount.get('CT');
        a.DE__c = stateCount.get('DE');
        a.FL__c = stateCount.get('FL');
        a.GA__c = stateCount.get('GA');
        a.HI__c = stateCount.get('HI');
        a.IA__c = stateCount.get('IA');
        a.ID__c = stateCount.get('ID');
        a.IL__c = stateCount.get('IL');
        a.IN__c = stateCount.get('IN');
        a.KS__c = stateCount.get('KS');
        a.KY__c = stateCount.get('KY');
        a.LA__c = stateCount.get('LA');
        a.MA__c = stateCount.get('MA');
        a.MD__c = stateCount.get('MD');
        a.ME__c = stateCount.get('ME');
        a.MI__c = stateCount.get('MI');
        a.MN__c = stateCount.get('MN');
        a.MO__c = stateCount.get('MO');
        a.MS__c = stateCount.get('MS');
        a.MT__c = stateCount.get('MT');
        a.NC__c = stateCount.get('NC');
        a.ND__c = stateCount.get('ND');
        a.NE__c = stateCount.get('NE');
        a.NH__c = stateCount.get('NH');
        a.NJ__c = stateCount.get('NJ');
        a.NM__c = stateCount.get('NM');
        a.NV__c = stateCount.get('NV');
        a.NY__c = stateCount.get('NY');
        a.OH__c = stateCount.get('OH');
        a.OK__c = stateCount.get('OK');
        a.OR__c = stateCount.get('OR');
        a.PA__c = stateCount.get('PA');
        a.RI__c = stateCount.get('RI');
        a.SC__c = stateCount.get('SC');
        a.SD__c = stateCount.get('SD');
        a.TN__c = stateCount.get('TN');
        a.TX__c = stateCount.get('TX');
        a.UT__c = stateCount.get('UT');
        a.VA__c = stateCount.get('VA');
        a.VT__c = stateCount.get('VT');
        a.WA__c = stateCount.get('WA');
        a.WI__c = stateCount.get('WI');
        a.WV__c = stateCount.get('WV');
        a.WY__c = stateCount.get('WY');
        a.DC__c = stateCount.get('DC');


        accountsToUpdate.add(a);

    }
    //End Loop - Account

    update accountsToUpdate;

}

 
The APEX Dev guide says that you can use a helper method to simplify doing @mentions in chatter posts. I can't get the helper mothod to work. I am getting an error using the example code from the github site. 

Dev Guide:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_post_feed_element_mention.htm
Link to helper on github:
https://github.com/forcedotcom/ConnectApiHelper

Code:
ConnectApi.FeedItem fi = ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hey there {005D00000015tjz}, how are you?');
Error Message:
Illegal assignment from ConnectApi.FeedElement to ConnectApi.FeedItem
 
Can anyone tell me the correct syntax for adding an IMG to the headerValue property? 

I currently have this code which displays the image on the inputField line.
<apex:column headerValue="Election Status">
                    <img src="/resource/acorn" title="   {!$ObjectType.Employee_Session_Benefit__c.Fields.Election_Status__c.inlineHelpText}" height="13" width="13" />
                        <apex:inputField value="{!rev.Election_Status__c}" rendered="{!paperRender}" />
                        <apex:outputText value="{!rev.Election_Status__c}" rendered="{!!paperRender}" />
                    </apex:column>

I want to move the <IMG... line up to the headerValue.

Here is a screenshot of how it currently looks. I want to move the image, and help text, to the area where the green arrow is pointing. 

User-added image

Any suggestions? 

 
We have images that are used in formulas in Sandbox like this:
CASE( Session_Status_Picklist__c,
"Complete", IMAGE("/servlet/servlet.FileDownload?file=01518000000EvIC","! Completed",50,50),
"In Progress", IMAGE("/servlet/servlet.FileDownload?file=01518000000EvI2","! In Progess",50,50),
"Under Admin Review", IMAGE("/servlet/servlet.FileDownload?file=01518000000EvIW","! Under Review",50,50),
""
)
When I move the images to Production the ID value for the image will  change.

Is there a better way to reference images so that they can be referenced in both Sandbox and Production? Maybe the thing called Static Resource which I haven't used yet.  

 
I am using the login flow to display an alert to our users about maintenance and I want to force a log out once they click Finsih in the flow. I have tried to use the hidden commands for logout but i can't get the log out action to work. The message is displayed to the user but after they click finsih they log right in. 

Overall Flow:
User-added image

Creating variable:
User-added image

Displaying the message to user:
User-added image

Using assginment to set value of variable: I already have it set to True as default value but thought I might need to do it again. 
User-added image

Can anyone spot what I have done wrong here? 
 
I need a formula to count the number of times a semi-colon appears in a variable. This is actually for visual flow but it is a formula like any other in Salesforce.

Any ideas? I need the count not just a TRUE or FALSE result. 

My overall goal is I need to compare the values captured from a  multi-select picklist and identify if values were either added or removed from the list. So I plan on counting the number of ; and then using a decision module to take appropriate action on another object. 

Here is an example:
09:00:25:612 FLOW_VALUE_ASSIGNMENT 3327be5ac80f0d842d9d2f061289153095dc09d-1678|varTMPriorValues|BM Web Enroll;We Care
So I need to get back 1 from this variable. 
 
09:00:25:612 FLOW_VALUE_ASSIGNMENT 3327be5ac80f0d842d9d2f061289153095dc09d-1678|varTMValues|Aflac;BM Web Enroll;We Care
And I should get 2 back from this variable. 

So I can do my decision and know that values were added to the list. 

 
Is there a way to run a trigger or class when a user clicks the New record button? 

For example, I want a bit of code to run when the user clicks the New Account button. This way I can show them an alert or other message before they put an details in for the new record and click Save which fires an existing trigger. 

I need osmething like "onload Insert"...
Hi, I am trying to write my first trigger and need some help. 

We have a custom object called Employee that has a field named "Scheduled Review Date". 
I need to create a trigger that upon creation of an Event record this field is updated with the date from Event in field "StartDateTime" < API name. The Related to (who) field on event is my employee. 

I have come up with this so far:
trigger ScheduledReviewDate on Event (after insert) {
    for (Event e: trigger.new){
    
    }
}

I'm not sure where to go from here. I think I need to query employee and then put the field update but I don't really know how to do this. 

I think this is pretty simple so hopefully someone can point me in the right direction. 

Thanks!
Matt

 

Hi,

 

I would like to be able to show a gif spinner on my visual force page as I am doing something on the background like loading data or waiting for data to come back before I update the page.

 

It will be ideal if I can replace apex:tags with a stylesheet that will be turned off or on based on user click.

 

 

Does anyone have a good solution for that I ma not very ajax savvy per say so any ideas will be appreciated.

 

 


Thank you.