• hemm
  • NEWBIE
  • 255 Points
  • Member since 2004

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 119
    Questions
  • 294
    Replies

One of the SFDC bloggers I often follow,  Perspectives on Salesforce,  recently posed the following question: how do i cast an object result from a dynamic query to a datetime variable?

 

Well, here is how I did it.  In this instance, I have a Lead Distribution System.  This controller evaluates the volume of Leads that a user is able to pull on a daily basis, tracking values like languages spoken, extra leads allowed for the day, etc.  One variable it tracks, is the last day the User pulled.  

 

(I've only included the query and the setting of variables as well as me casting to a list by calling those variables, including Date).

 

 

//Call all the values to an object instance, to then be passed to variables public User usr = [Select TruePerDiem__c, LeadPullQueues__c, PerDiem__c,Last_Pulled__c,Open_Leads_Owned__c,PulledXDaysAgo__C, Lang1__c, Lang2__c, Lang3__c, Lang4__c, Lang5__c from User where Id = :userinfo.getuserid() LIMIT 1]; //Create variables to receive dynamic values from above query public String Queue = usr.LeadPullQueues__c; public Double NewMAX= usr.PerDiem__c; public Integer NewDiem = newMax.intvalue(); //LOOK HERE - This is where I am pulling date!!!! Public Date LastPulled = usr.Last_Pulled__c; //Here is where I cast to a list with a SOQL Query, using dynamic variables from above //(please note, I removed alot of the variables I create in my controller for the sake of brevity. List<Lead> leads = [select Id,ownerid,PulledYes__c,ELPLang__c,Priotizer__c from lead where ownerid = :Queue AND (ELPLang__c LIKE :Lang1 OR ELPLang__c LIKE :Lang2 OR ELPLang__c LIKE :Lang3 OR ELPLang__c LIKE :Lang4 OR ELPLang__c LIKE :Lang5)

 

Now, in my example, I use the LastPulled Date Variable for ternary, if/else logic but it could easily be applied to a SOQL statement.  ("...where Date = :LastPulled).

 

Does anybody else have any examples of other approaches.  This really is a great opportunity to learn about dynamic queries, a rich capability of Apex.

 

 

Have the following enum in a controller extension:

 

 

public enum ApprovalState { NotRequired, Required, Pending }

public ApprovalState CurrentApprovalState { get; set; }

 

 

And the following VF snippet:

 

 

<apex:commandButton disabled="{!currentApprovalState != ApprovalState.NotRequired}" />

 

When I attempt to save the VF page, I get "Save error: Unknown property 'Quote__cStandardController.ApprovalState'"
 
 Am I using the wrong syntax to access the enum data type?

 

 

 

 

Hi, I have installed the "Sidebar Summary" and it works great.
 
But now when I tried to deploy another class, it says:
 

Test Class VFController_Sidebar_Summary
Tests Run 1
Test Failures 1
Code coverage total % 100
Total time (ms) 0

Class VFController_Sidebar_Summary testVFController_Sidebar_Summary 136 System.Exception: Too many query rows: 501 Class.VFController_Sidebar_Summary.getPastDueOppty: line 52, column 8
Class.VFController_Sidebar_Summary.testVFController_Sidebar_Summary: line 68, column 14

This test calss is not in the "package.xml” file. So why it runs this test? Not the one I specified in "package.xml"? Should they be independent?

 

 

  • December 16, 2008
  • Like
  • 0
How are requests to http://mycompany.force.com/services/apexrest counted (or not counted) as page views? These are calls to Apex REST services made available via a Site. These DO take an API call, but do they take a Sites page view too?

Can someone from Salesforce please help get this answered for me? It's an answer that belongs on the help article linked in this post.

https://help.salesforce.com/HTViewHelpDoc?id=sites_limits.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=sites_limits.htm&language=en_US)
  • April 22, 2015
  • Like
  • 0
We are hosting an Apex REST endpoint on our salesforce site. The URL path to the service is similar to https://mycompany.secure.force.com/services/apexrest/endpointName.

I am confused as to whether a hit against that endpoint will count as a Site Pageview, API call or both? It appears that it is counting as a pageview, but it seems to me that it should not and should only count as an API hit. Please clarify.
  • June 27, 2014
  • Like
  • 0

We have an iOS app and I'd like to link to a Salesforce record in the Salesforce Mobile app rather than sending the user to Safari. 

 

Does the Salesforce Mobile app have a URLScheme so that 1) we can check if the app is installed and 2) we can link to a record in that app?

 

An example of this kind of thing is what Google did in there Google Maps app for iOS. See https://developers.google.com/maps/documentation/ios/urlscheme. I'd like something analygous to that, but with Salesforce Mobile

  • January 15, 2013
  • Like
  • 0

I like using Chatter Files for Attachments because they are prettier and searchable. The downside is that, when you add one to an Opporutunity, you don't see it as an Attachment on the Account like an old-skool Attachment would.

 

So I am working on a trigger where, if a user posts a Chatter File to an Opportunity, it also links it up to the Account. Sample code is below. I am successfully checking for it being a Chatter File (ContentPost) and only running when linked to an Opportunity, but the trigger runs whether I am adding a new file and also if I am associating an existing file to an Opportunity.

 

Any ideas how to determine whether the ContentPost is using a new Chatter File or an Existing one?

 

for (FeedItem f: fis){

    String parentIdString = String.valueOf(f.parentId);

    if (parentIdString.startsWith(Opportunity.sObjectType.getDescribe().getKeyPrefix()) && f.type == 'ContentPost'){
        Opportunity o = [select id, accountId from Opportunity where id = :f.ParentId limit 1][0];
        if(o.AccountId != null){
            FeedItem newFI = new FeedItem();
                newFI.Type = 'ContentPost';
                newFI.RelatedRecordId = f.RelatedRecordId;
                newFI.ParentId = o.AccountId;
                newFI.title = f.title;
            insert newFI;
        }

    }

}

 NOTE: I am already aware of the issue with querying and DML in the loop. I will fix that later. I am mostly concerned with getting the scenario correctly handled.

 

 

  • August 31, 2012
  • Like
  • 0

I need to confirm I can put a Flow on a Salesforce site before I proceed to use this tool. I have created an extremely simple flow that does nothing more than show some screens. Welcome --> Hello --> Finish.  I am on Spring 12 already.

 

I added the flow to a Page using <flow:interview name="My_Flow"/>.

 

I put that page on my Site. 

 

When I go to the page on Sites, I get an Authorization error.

 

Is there anything else I need to do to make this work? One thing I have noticed is that user records have a check box for "Flow User". I went to the user record for the guest license of the site, but I don't see that checkbox to check. 

 

I have read the help and understand the steps to enable it on a Site, but can't make it actually work.

 

  • February 08, 2012
  • Like
  • 0

I am loading the AJAX toolkit into a Visualforce page because the API has functionality in it that Apex does not support. Whether the user has API access or not, the script loads fine and the sforce object is created.

 

Within the sforce Javascript object, I don't see anything indicating whether a user has API access or not.  If I run a call (e.g. sforce.connection.describeGlobal()), a user without API access returns an error.

 

When the page loads I want to have a script invoked that tests whether the existing user has API access or not and result it in a true/false variable that I'll keep on the page.  I will then use the results of that variable to turn on/off functionality for the page.

 

Can anyone help with a safe function to run that accomplishes can test whether API access is turned on and return true or false?  I've tried, but have had trouble catching all the possible errors.  I need it so that no Javascript errors are thrown because that kills IE and looks ugly in the console of the other browsers.

  • January 27, 2012
  • Like
  • 0

I am working with Dynamic Visualforce Components to popup a jQuery dialog to display the related lists for a record on my page.

 

Below is an example.  Notice the getDVF method. This is where I am using the recordID and building the related list objects.  My goal is to show the related list, but remove the header and footer (which I can do by clearing the facets), but I'd also like to clean up the body.  I'd love to get rid of the Action column for example and adjust all links to open with a target="_blank".

 

public with sharing class test_DynamicVF {

    public String recordID {get; set;}
    
    public PageReference runButtonClick(){ return null; }
    
    public Component.Apex.RelatedList getDVF(){
        if(recordID != null){
            Component.Apex.RelatedList det = new Component.Apex.RelatedList();
            det.subject = recordID;
            det.list='Contacts';
            Component.Apex.OutputText header = new Component.Apex.OutputText(value='');
            det.facets.header=header;
            return det;
        }
        
        return null;
    }
    
}

 

I see 2 choices to do this...

 

  • (preferred) Get the standard related list and edit it.
  • Build a new dataTable from scratch, but I would need the results of the describePageLayouts data which is not available in Apex (only the API)

To accomplish the first option, is there any way (via Apex) for me to obtain the body conten and modify it?  In the example above, this would be obtaining the body content of the related list and then modify it.

  • January 10, 2012
  • Like
  • 0

I am using JSON.serialize() to output some custom classes JavaScript to a Page.  I am serializing a custom class and that class has a transient property that includes the Schema.DescribeFieldResult object.

 

On every instance I have access to (except CS1), it serializes fine.  On CS1, I get the error Apex Type unsupported in JSON: Schema.DescribeFieldResult.

 

Thoughts?

 

I am hoping CS1 is out of date and just needs an update.  I am worried, though, that CS1 has newer code and I will start seeing this issue on other instances in the near future.

  • December 28, 2011
  • Like
  • 0

For the life of me, I cannot get this to work.

 

I have a remoteAction method returning a URL String. I am then trying to use window.open to open that URL.  For some reason, the browser will not launch a new window and open that URL.  I am certain my code is hitting that line.  Below is a generic example of what I am trying to do.

 

mynamespace.mycontroller.getMyURL(inputString, function(result, event){ 
        	if (event.status) {
        		window.open (result);
       	       	}
       	       	, {escape:true});

 

  • December 17, 2011
  • Like
  • 0

In Winter 12, @remoteAction methods were enhanced to allow "public" methods to be used in Visualforce controllers.  That's great.  I am curious about the profile requirements, though.

 

What I am finding is that, for non-admins, the Controller class needs to be assigned to their profile, but for admins it does not. I was under the impression that having a remote action in the main controller for a page would be enough.  By the user being assigned to the Page, they'd automatically have access to that page's remote action methods, but that doesn't seem to be the case.

 

My main concern is that I am introducing remote actions into a managed package app and it would be likely that my users are not assigned to the controller class in their profile.  I'd like to push upgrade the change so it "just works", but am worried about the side effects.

 

Is the requirement for apex class assignment in the Profile by design or is it a bug? 

  • December 13, 2011
  • Like
  • 0

The Swarm app (my client is on version 3.0) calls @future methods in its triggers. If a record is updated by an @future method or a batch process, it throws an error because you can't call an @future method from a batch transaction or a future one.

 

The triggers need to be updated to check system.isFuture() and system.isBatch() before invoking those calls.  Not doing this makes the swarm app not play nice with other AppExchange apps!

  • November 11, 2011
  • Like
  • 0

Given an org ID, are there things I can interpret from it? For example, I heard somewhere that character #4 referenced the instance someone is on (or maybe the one they were originally on). It'd at least be a way to determine production vs. sandbox.

 

Is there truth to that?

 

Are there other characters that have special meaning in an Org ID?

  • November 11, 2011
  • Like
  • 0

According to the Apex documentation and, I swear, up until yesterday, a Batch Apex job would create a single record in the AsyncApexJob object with a JobType = 'BatchApex'.  This record would keep track of the job including total batches, errored batches, number processed, status, etc.

 

Today I started seeing a 2nd record created for a batch job with a JobType = 'BatchApexWorker'.  It seems that this record has a Parent Job Id of the main BatchApex record, but it's this record that tracks the job while it runs.  Once the job completes, the main BatchApex record gets updated.

 

Is this the plan going forward? When did this change? It's not documented anywhere.  in fact, the docs specifically say to use the BatchApex record.

  • July 26, 2011
  • Like
  • 0

From what I understand, there is no easy way in SOQL to do a My Team's query.  A "My" query is a simple OwnerId = :UserInfo.getUserId(), but nothing this simple for My Team's.

 

Can anyone suggest a logical way to build SOQL that mimics the concept of My Team's?

  • May 04, 2011
  • Like
  • 0

I am working on something where I want to allow an admin to assign items to a Public Group.  Then, at runtime, I need to determine what Public Groups a user is in (directly or via Roles / Roles + Subordinates) and display the appropriate items.  Because Public Groups can be complicated having other Public Groups as Members and also Roles & Subordinates, figuring out the Groups a user is in can be difficult.

 

I started a conversation on Twitter about it and then did some research and have a starting point.  I'd like to encourage others to help me vet this and then it could become a Cookbook item down the line.  Here's what I got...

 

I think this can be done in 2 steps without much looping.  From what I can tell, the Group table can contain all kinds of Groups ("Regular" Public Groups, Roles, Soles & Subordinates, Queues, etc.).  The Group Member table seems to only contain pointers to Users or to Other Groups.  Groups that are copies of Roles and Roles & Subordinates have a Related Id filled in.  

 

I believe the following 2 queries could determine the Public Groups that a User is actually in...

 

1) Query the Group table to get the Group records where the Related Id = the users's role.  We could filter for Type of Role or RoleAndSubordinates, but it seems that anything with a RelatedId filled in is one of those types.  This query is essentially getting the Group records that mirror our Role record.

 

 

List<String> roleRelatedGroupIds = new List<String>();
for (Group g : [SELECT id, RelatedId, Type FROM Group where RelatedId= :UserInfo.getUserRoleId()]{
   roleRelatedGroupIds.add(g.id);
}

 

2) Next we query the Group Member table for records where our user is specifically assigned and  also include records where our role is assigned.

 

List<String> allGroupIDs = new List<String>();
for (GroupMember gm : [SELECT Id, group.id, group.name, group.type FROM GroupMember where (UserOrGroupId = :UserInfo.getUserId() AND group.type='Regular') OR (UserOrGroupId IN :roleRelatedGroupIds AND group.type='Regular')]{
allGroupIDs.add(gm.group.id);
}

 

 

I'd need to hack at this given lots of users and lots of Group Types like Queues, Territories, Roles, Public Groups, etc.  From what I've been able to test, this works.

  • March 09, 2011
  • Like
  • 0

I am looking to add some logic into an AppExchange app that cares about the type of user logged in.  I see 2 places where I can get similar information, but it's a bit different.  I am wondering what the recommendation is as to how these values should be used and/or which is more reliable.

 

1) User.UserType - this is accessible via UserInfo.getUserType();

 

2) License Name - this is accessible when querying User and selecting the profile.userlicense.name field.

 

My main desire is to know whether a Guest user is accessing the functionality (Salesforce Sites). Are these 2 values equally reliable?

  • March 03, 2011
  • Like
  • 0

I am working on providing users a wizard for creating queries.  I have it working, but occassionally get the message "Entity 'Task' is not supported for semi join inner selects"

 

The query resembles this...

 

 

select id, name from opportunity where id in (select whatid from Task where type = 'special activity type')

 

 

I totally understand that some objects cannot be used in this type of filter.  In the UI where they create the rule that generates this query, I want to EXCLUDE objects that do not support this kind of filtering (e.g. Tasks, Activity History, etc).  Looking at the describe information, I cannot figure out a way to determine this.  

 

Is there anything in the object or field describe that tells me this?

  • November 04, 2010
  • Like
  • 0

In reviewing the View State Inspector, I often see the same variable listed many times.  Instead of giving me a Data Type, it says "Reference to variableName".

 

If I am making multiple references to the same field in a VF page, does each instance take up View State?  Shouldn't it only be the variable itself that it's in the View State?  If the former, what's the best practice to minimize that impact?

 

 

  • October 28, 2010
  • Like
  • 0

I currently have apex:include tags in a VF page that dynamically insert other pages into the master page.  The pages being inserted have the same Controller as the master page.  My main reason for doing this is organization so I do not have one huge page.  I am keeping some JavaScript in the included pages and that JavaSCript uses values in the controller to operate.

 

Below is a dumbed down representative sample of the code.   In my main page, I will re-render the dynamicJavaScript panel to execute code.

 

 

<apex:outputPanel id="dynamicJavaScript">
        
  <apex:include pageName="js_Script1"  id="js_Script1" rendered="{!mode='x'}"/>

  <apex:include pageName="js_Script2"  id="js_Script2" rendered="{!mode='y'}"/>

</apex:outputPanel>

 

My main questions have to do with View State and efficiency.  

 

  • Is there a downside to doing things this way?  
  • Do multiple controllers get invoked (one from each page) that all take up memory? Or does VF figure it out to run under 1 controller.
If needed, I could pull all the JavaScript into the main page, but it's nice to do it this way from a development standpoint.

 

 

 

  • October 28, 2010
  • Like
  • 0

On a VF page, I have a pageBlockTable.  There are times where there are more than 1000 records in the collection to be rendered.  When this occurs, the Visualforce collection limit of 1000 is hit and the page doesn't load.  I need to figure out a creative solution for getting around this.  In the end...

 

  1. I need all records to render on the page. If I do any pagination, it'll happen client-side after the records are loaded in the HTML.  I know the first responses to this will be about whether I really need to have all those records on the page and how there is doubt about whether I need to, but for the purposes of this forum post, please work with me here.
  2. I want to keep the look and feel of a pageBlockTable if possible.

 

When not using pageBlockTables, I have used a construct similar to the following to get through a collection of more than 1000 items.

 

<apex:repeat value="{!myCollection}" var="item" rows="1000" first="0">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="1000">
{!item.text}
</apex:repeat>
<apex:repeat value="{!myCollection}" var="item" rows="1000" first="2000">
{!item.text}
</apex:repeat>

 

pageBlockTable has the rows and first parameters, but if I do that, I'd be getting a new pageBlockTable everytime.

 

The options I can think of are:

 

  • Get a creative solution from the forums to actually utilize the pageBlockTable (purpose of this post)
  • Use apex:dataTable and try to use style classes to mimix the pageBlockTable look and feel. This is a nice possibility I haven't tried yet.
  • Use apex:repeat tags and make up my own HTML styling

 

Any help is appreciated.

 

 

  • September 13, 2010
  • Like
  • 0
According to the documentation here the UserInfo (and global variable) should indicate which theme the user is currently using. This works fine, except that in mobile devices, the theme always indicates SF1 (Theme4t). Even if the user is using a mobile browser (Safari on iPad for instance) and is in the full Salesforce site in classic view. This makes it impossible to treat the SF1 app or lightning vs classic UI differently on any mobile device. I've tested this on iPad, iPhone and Android (Chrome browser).

Is this by design? If so, this should be noted in the documentation.
  • June 21, 2016
  • Like
  • 0
Hi,

Because of SSLv3 Poodle vulnerability, we have turned off SSLv3 support on our web server. This in term is causing Salesforce outbound messaging to fail.

Is there a work around with this from Salesforce end?

The outbound messaging processing issue was resolved once we turn SSLv3 back on our web server.

Ted Tsung
We are hosting an Apex REST endpoint on our salesforce site. The URL path to the service is similar to https://mycompany.secure.force.com/services/apexrest/endpointName.

I am confused as to whether a hit against that endpoint will count as a Site Pageview, API call or both? It appears that it is counting as a pageview, but it seems to me that it should not and should only count as an API hit. Please clarify.
  • June 27, 2014
  • Like
  • 0

I like using Chatter Files for Attachments because they are prettier and searchable. The downside is that, when you add one to an Opporutunity, you don't see it as an Attachment on the Account like an old-skool Attachment would.

 

So I am working on a trigger where, if a user posts a Chatter File to an Opportunity, it also links it up to the Account. Sample code is below. I am successfully checking for it being a Chatter File (ContentPost) and only running when linked to an Opportunity, but the trigger runs whether I am adding a new file and also if I am associating an existing file to an Opportunity.

 

Any ideas how to determine whether the ContentPost is using a new Chatter File or an Existing one?

 

for (FeedItem f: fis){

    String parentIdString = String.valueOf(f.parentId);

    if (parentIdString.startsWith(Opportunity.sObjectType.getDescribe().getKeyPrefix()) && f.type == 'ContentPost'){
        Opportunity o = [select id, accountId from Opportunity where id = :f.ParentId limit 1][0];
        if(o.AccountId != null){
            FeedItem newFI = new FeedItem();
                newFI.Type = 'ContentPost';
                newFI.RelatedRecordId = f.RelatedRecordId;
                newFI.ParentId = o.AccountId;
                newFI.title = f.title;
            insert newFI;
        }

    }

}

 NOTE: I am already aware of the issue with querying and DML in the loop. I will fix that later. I am mostly concerned with getting the scenario correctly handled.

 

 

  • August 31, 2012
  • Like
  • 0

while migrating though force.com Eclipse i am getting this error

 

File Name: objects/Opportunity.object
Full Name: Opportunity.geopointe__Geocode__c
Action: NO ACTION
Result: FAILED
Problem: Cannot create a new component with the namespace: geopointe. Only components in the same namespace as the organization can be created through the API

 

Can any one suggest...............

I need to confirm I can put a Flow on a Salesforce site before I proceed to use this tool. I have created an extremely simple flow that does nothing more than show some screens. Welcome --> Hello --> Finish.  I am on Spring 12 already.

 

I added the flow to a Page using <flow:interview name="My_Flow"/>.

 

I put that page on my Site. 

 

When I go to the page on Sites, I get an Authorization error.

 

Is there anything else I need to do to make this work? One thing I have noticed is that user records have a check box for "Flow User". I went to the user record for the guest license of the site, but I don't see that checkbox to check. 

 

I have read the help and understand the steps to enable it on a Site, but can't make it actually work.

 

  • February 08, 2012
  • Like
  • 0

I just started to use JavaScript remoting. It seems the function called from JavaScript remoting should be global in a managed package.

Oh no, that is a bummer. I do not like to make any Apex class or function global unless it is extremely necessary. Once it is global I cannot change the name of the controller and the global function.  

 

Thanks,

Dipu

  • January 13, 2012
  • Like
  • 0

In Winter 12, @remoteAction methods were enhanced to allow "public" methods to be used in Visualforce controllers.  That's great.  I am curious about the profile requirements, though.

 

What I am finding is that, for non-admins, the Controller class needs to be assigned to their profile, but for admins it does not. I was under the impression that having a remote action in the main controller for a page would be enough.  By the user being assigned to the Page, they'd automatically have access to that page's remote action methods, but that doesn't seem to be the case.

 

My main concern is that I am introducing remote actions into a managed package app and it would be likely that my users are not assigned to the controller class in their profile.  I'd like to push upgrade the change so it "just works", but am worried about the side effects.

 

Is the requirement for apex class assignment in the Profile by design or is it a bug? 

  • December 13, 2011
  • Like
  • 0