• michaelforce
  • NEWBIE
  • 230 Points
  • Member since 2006

  • Chatter
    Feed
  • 7
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 251
    Replies

Is it possible to remove the Required Information part on a Visual Force page? When you add a <apex:pageblocksection> it automatically puts a line that says Required Information on the first pageBlockSection. I want to remove it because I read that you cannot easily put that red line on custom text fields like <apex:outputText>. So I didn't want to confuse the user by saying that the red line denotes a required field.

Hi All,

 

I have records in contacts object which are having  two types of 'contact type' like 'CEO'  and 'Manager',

 

 

i don't want users to delete the contact records which are of  'CEO' , this can be achieved through trigger, but i want to show custom message in the page.

 

how can this achieved. 

 

thanks in advance.

Good day,

 

May i know what are the way to get field ID ?

 

normally we use document.getElemementByID('myField')

 

but is there any better way ?

 

Thank you !

Message Edited by Nakata on 12-07-2009 11:41 PM
  • December 08, 2009
  • Like
  • 0

I have a VF page with matching controller to make some links for our reps. I want to append the value from the last name field from the running user's User object to my link. In my controller i have the main url hardcoded as a string and then i add parameters to that string depending on the field values. But when if i do something like

 

link = link + 'spid=' + User.LastName;

 

What I actually get is "spid=LastName"  

 

If i try to add the value as a apex:param to a link the code "%3f" shows up where it should have an "&". 

Hi,

 

I'm converting an exisiting html/css/javascript (small amount) site to the force.com and have ran into some roadblocks I could use help with. 

 

The application makes use of an iframe and has a javascript function to scroll the content within the frame. This function works if linked to an external site, so I know the javascript is working, but when linked to an internal salesforce page it does not work. I think this is due to the 'page editor' function. Is there a way to preview the site with this function disabled?

 

Thanks much

I need to create VF page with button which creates new element related to current and add it to list. I want to fill automatically master field and maybe some additional fields.

 

Can I extend code below some how to make it?:

 

 <apex:commandButton action="{!URLFOR($Action.CF_OtherOp__c.New)}" value="new bussines opportunity"/>

 

If not how its possible to implement? 

  

Thanks,

  Kostja 

Hello,

 

Regarding the AsynResponder in the Flex toolkit, I'm looking for a decent explanation on why I would use the Context object as part of my AsyncResponder setup. I've seen a few posts explaining some past updates to it, but I'd love to understand what I can do with it.

 

Ultimately I'm trying to build a DAO framework for my application that needs to get data on-demand from SFDC.  I then populate control widgets in my Flex application, but I'm having trouble because the AsyncResponder is Asynchronous, and I don't want to build the AsyncResponder block over-and-over again for the same generic queries that might be used accross multiple layouts/controls.

 

If anyone has any practical examples or advice on a better way to do this, please pass along.

 

Links to other meaningful posts/articles accepted. 

 

Thanks,

 

Dave 

I have a managed package, in that managed package is a visualforce page, in that page is a link that is defined using URLFOR($Action.Account.View,d.account.Id).  It works well... UNLESS the customer who has installed this package creates a Visualforce Page of their own that overrides the Account View button.  When this happens, the URLFOR spits out the URL of their customer page but with the namespace of my package... which obviously leads to "Page No Longer Exists".  This seems like a bug... URLFOR should be smart enough to know the page is outside my package and hence should not have the namespace.

Anyhow, my workaround will be to check for visualforce pages in the URLFOR and if it finds one outside the package, then it will simply send them to /{!account.Id}... this will attempt to send them to the standard view page and let Salesforce do any redirect as needed.

My questions for you all:
1) Is this the best way to workaround this?
2) Do we think this is a bug that should be reported or is it by design?
I've built a native application which needs Page Layout info.  You can't call describeLayout directly in Apex, so my workaround is to use a web service callout to call the SOAP API.  It works really well, BUT a few customers are unable to use the app because the call fails due to the describeLayout response being greater than the maximum response size that Apex can digest (3MB).

I have no idea why the response is so larger... the orgs in which I've investigated have a very reasonable number of fields, layouts, record types, etc.

So my questions for you experts:  What the heck is in this response that could be making it so large?  How can I work with the customer to somehow get the response size down?  Any recommendations?
I've come across a very specific but easily reproduceable bug.  What happens is that if you have a form on a Visualforce Page with some inputFields on it which include two lookup fields, one dependent on the other via lookup filtering, and you do a partial rerender of the page, the cursor will jump from whatever field it is on up to the first field on the form.

I know, I know... that's pretty specific.  But several of my customers have hit this.  So I am looking for confirmation that it is a bug, and more importantly I am looking for advice on how I can combat this.

How to Reproduce:

First create two lookup fields on the Account object.  One lookup to the Account object and one to the Contact object.  The lookup to the Account object can be named "Distributor__c" and the one to the Contact "Distributor_Contact__c".  Then on the Contact lookup field, add the following lookup filter:

User-added image

The create this Apex Class...

public with sharing class cursorJumpExtension {

    public Integer refreshCount {get;set;}

    public cursorJumpExtension(ApexPages.StandardController controller) {
        refreshCount=0;
    }

    public void refreshPlus(){
        refreshCount+=1;
    }

}

Then this Visualforce Page...
 
<apex:page standardController="Account" extensions="cursorJumpExtension">
<apex:form >

    <apex:actionFunction name="doRefresh" action="{!refreshPlus}" reRender="refreshing" immediate="true"/>

    <apex:pageBlock id="refreshing">
   
        <script>
            window.setTimeout(doRefresh,3000);   
        </script>
   
        This block re-renders every 3 seconds.<br/><br/>
        Last refresh at: {!NOW()}<br/>
        Number of times refreshed: {!refreshCount}
    </apex:pageBlock>

    <apex:pageBlock >
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!Account.Name}"/>
            <apex:inputField value="{!Account.Distributor__c}"/>
            <apex:inputField value="{!Account.Distributor_Contact__c}"/>
            <apex:inputField value="{!Account.website}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>

</apex:form>
</apex:page>


Now navigate to the Page and put the cursor in the website field.  You will see that the next time the top box refreshes, the cursor jumps to the first field!  Annoying!  Then you can go back to your lookup field and deactivate the lookup filter... OR simply change it to a different kind of filter that doesn't reference another field, and the cursor jumping phenomena stops.

Anyone know what I can do here??

I thought this error was a thing of the past when Salesforce put out a fix for resolving Visualforce session Ids several years ago but it's apparently hard to kill.  Here are the facts:

 

The error is happening when using the session Id from the global API variable with the AJAX toolkit (see code below)

The Visualforce Page in question is part of a managed package

The customer hitting the error is doing so in a sandbox, Unlimited Edition

This app is working correctly for hundreds of other customers without a problem

The "lock session to originating IP" setting is turned OFF

Viewing Source on page confirms that a session Id is being populated on this line of the JS

 

For whatever reason this customer is getting "Invalid Session Id".  I could begin the "shots in the dark" and try going back to old school tactics like getting the session Id from the Apex controller instead of a merge field... but why is it working for all other customers and not this one?  Also, I don't want to do too much trial and error because its a huge PITA to uninstall in their sandbox, reupload a beta package, an reinstall for every little thing I want to try and test.

 

Any ideas?

 

<script src="../../soap/ajax/24.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">
    
        sforce.connection.sessionId = '{!$Api.Session_ID}';

</script>

 

I scoured the message boards and don't see anyone else who has run into this.  I'm thinking it's a bug, although not a terribly detrimental one.

 

I have a "without sharing" class that needs to know if the current user has access to a list of records.  So it uses a separate "with sharing" class to figure it out... works well.  Then to take it one step further and see if they have access to edit you have to get creative, and the knowledge in this forum told me the only way is to attempt an update, see which records failed and then do a rollback to a savepoint... this too works well, woohoo.

 

The weird thing, is that the records that are updated in this check will then show up in the users recent items.  I could see how maybe this is a good thing if the records were actually updated... but they weren't the change was rolled back.  I guess it's a bug.. thoughts?

I'm not sure if this is expected behavior or a bug, or if there is something I'm missing.

 

As of Winter '11, InputField components will load on your page with the default value for the corresponding field.  Very cool, and it even works for Dynamic Visualforce too.  But I've noticed that it will only work if the field is included at the time the page is loaded.

 

So if you have anything dynamic going on that causes an inputField to be added to the page such as an action runs and "reRenders" a section causing a new inputField to be rendered within... or if you use Dynamic Visualforce and your controller passes back an inputField that wasn't previously included in the dynamicComponent.  The newly added InputField will be empty, any default value is ignored.

 

I've even tried to be sneaky and use a wizard approach so that the controller can do some calculating and initalization and interaction with some AJAX on the first page and then when it is ready to display my inputFields it forwards to another page with the same controller.  So the controller and all data remains, but the user is on a fresh page that will display the input form... this didn't work.  So it's clear that the inputField will only have the default if it is part of the page when BOTH the page AND controller (and/or extensions) load.

 

Bug?  Or is this how it should be?

 

Of course if the field describe result "getDefaultValue()" method actually did what the name implies then I could just fetch it myself :-)

 

 

Hey folks,

 

I have some Visualforce pages in a managed package that I would like to expose to ALL users in an org (ALL meaning those with a license to my app and those who do not) and based on whether they have a license or not it will act differently.

 

At first glance I thought, hey cool they have a function for exactly that... I can call UserInfo.isCurrentUserLicensed('myApp') to find out and act accordingly.

 

Upon further thought, I realized that no code from the package can ever be run by unlicensed users in the first place, so there is no way to perform such a check... am I missing something?  Or is this method not able to be used from within a managed package?

 

You can use it in your own code to see if a user has a license to something else you've installed... or one partner app could use it to see if you have their competitors product installed (LOL) but nether of those seem all that helpful.  Any idea what this method is good for?

 

In case you are wondering, this is another thread that explains what I am trying to accomplish which lead me to wonder about this method:  http://boards.developerforce.com/t5/Visualforce-Development/Action-Override-to-Managed-VF-page-breaks-other-users/m-p/442317#M50598

Hey folks, I've been playing with Dynamic Visualforce pretty heavily lately.  I noticed something funny and wanted to see if it is "normal" / expected behavior or not.  The deal is, when you have a dynamicComponent on the page and you reRender another part of the page (a section that doesn't contain the dynamicComponent) the get method for the dynamicComponent is still running again.

 

Below is an elementary example.  We have a dynamicComponent whose get method will return an empty PageBlock and has a debug statement to make it clear when that get method runs.  Then below that is a section with a button inside it that will reRender when the button is pushed without reloading the page (i.e. return type is void, not PageReference).

 

When you click the button and check the debug log for that button push, you will see that the "getTheBlock" method ran even though the dynamicComponent wasn't "supposed" to be reRendered.  Puzzling!

 

Page:

 

<apex:page controller="troubleController">
    <apex:form >

        <apex:dynamicComponent componentValue="{!theBlock}"/>
    
        <apex:outputPanel id="mySection">
            <apex:commandButton value="reRender below value" action="{!someAction}" reRender="mySection"/>
            <br/>{!now()}
        </apex:outputPanel>

    </apex:form>
</apex:page>

 Controller:

public with sharing class troubleController {

    public void someAction(){}

    public Component.Apex.PageBlock getTheBlock() {
    
        system.debug('The block is being got!');
    
        Component.Apex.PageBlock block = new Component.Apex.PageBlock();
        return block;
    }
}

 

Hey folks, I'm in a new role now, so I will be coding a lot more.  Looking forward to hanging out in here more often!

 

I'm working with Dynamic Visualforce at the moment (apex:dynamicComponent) to build a simple Lead form.  It's a long story why it has to be built dyamically.  I'm extending the standard Lead controller, and leveraging the standard {!save} method.  It works great when the record saves... they are brought to the new record and all the info they entered is there... woohoo!

 

The problem is when they click save but haven't filled in one or more required fields.  The form refreshes and correctly identifies the fields they forgot to populate and notifies them as is appropriate.  BUT, all the info they had entered is cleared out!

 

Here is a small example that shows what I mean:

 

Visualforce Page:

<apex:page extensions="dynamicTestController" standardController="Lead">

    <apex:messages />

    <apex:form >
        <apex:pageBlock mode="edit">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            
            <apex:dynamicComponent componentValue="{!mySection}"/>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Apex Controller:

public with sharing class dynamicTestController {

    public Lead theLead {get;set;}

    public dynamicTestController(ApexPages.StandardController controller) {
        theLead = (lead)controller.getRecord();
    }

    public Component.Apex.PageBlockSection getMySection() {
        
        Component.Apex.PageBlockSection section = new Component.Apex.PageBlockSection(columns=1);
        
        Component.Apex.InputField field1 = new Component.Apex.InputField();
        field1.expressions.value = '{!theLead.LastName}';
        
        Component.Apex.InputField field2 = new Component.Apex.InputField();
        field2.expressions.value = '{!theLead.Company}';
        
        Component.Apex.InputField field3 = new Component.Apex.InputField();
        field3.expressions.value = '{!theLead.Phone}';
        
        section.childComponents.add(field1);
        section.childComponents.add(field2);
        section.childComponents.add(field3);
        
        return section;
    }
}

 

 

 

You can see that when you populate LastName and Phone, but NOT Company and click save the form is cleared out... not cool!

 

I've concocted a workaround, which is to use a custom save method that returns nothing so I can avoid refreshing of the form.  I then use the apex:messages component to display any errors at the top of the page and redirect with JavaScript if there are no errors.  It works, but then errors that should be on a specific field are at the top instead and I would rather not have to rely on JS for navigation like that.

 

Any thoughts?

 

Cheers,

michaelforce

I have overridden the "new" and "edit" buttons for a custom object with a Visualforce page / Apex extension.  The constructor of the extension gets the "retURL" parameter from the currentPage().getParameters() like so:

 

 

theOpp = [select Id, Name, (select Id, Account__c, Opportunity__c, Role__c from Partners2__r) from Opportunity where Id = :ApexPages.currentPage().getParameters().get('retURL').substring(1) limit 1];

 

 

I have confirmed that all buttons available to our users to get to this screen always contain /OPPORTUNITYID as the retURL and thus I am just removing the slash and using the Id to query an Opportunity.

 

The problem is that it is randomly producing errors... stating the retURL parameter is null.  Then the same user can go back and try again and it works... totally sporadic.  So I am thinking maybe the constructor is running "too quickly" so the parameter isn't established yet?  Possibly I need to make this call in the "Action" of the page instead?  Any help is appreciated!

I've tried to migrate the translation for a custom object using both "Change Sets" and the IDE... both state that they succeed, but the translations don't actually migrate.  In the IDE I have tried migrating the "Translations" for the languages desired AND tried selecting the "objectTranslations" for the desired custom object... no dice.

 

Anyone have any ideas?  My customer spent a lot of time setting up the translations in the sandbox, and I will hate to have to tell them it has to be done all over again.

I have a visualforce page with both actionSupport and some JavaScript interacting with an actionFunction.  The controller for the page is a standard controller (custom object) with one extension.  The goal of both the actionSupport and actionFunction is simply to rerender parts of the page.

 

The funny part is that the rerendering pieces will only work if the user has populated the name field... or if the URL had an Id in it, which means the record loaded in the standard controller already had a name.  Either way, the fancy rerenders simply don't happen unless the record the page is working with has a name.  I'm sure that behind the scenes there is a logical explanation... but I am baffled.

 

To recreate the scenario I will paste below a very simple page, class combo that uses the standard account controller.  Once you have created these in your org, navigate to the page and WITHOUT entering a name, change the "Industry" field a few times... nothing will happen.  Then go and give it a name, then change the Industry field again... magically, the rerender begins to work.  Any ideas?

 

Page:

 

<apex:page standardController="account" extensions="testWeirdBugExtension">
    <apex:form>
        <apex:pageBlock>
        
            <apex:pageBlockSection>
                <apex:inputField value="{!theRecord.Name}"/>
                <apex:pageblockSectionItem>
                    <apex:outputLabel>Industry</apex:outputLabel>
                    <apex:selectList value="{!theRecord.Industry}" multiselect="false" size="1">
                        <apex:selectOption itemValue="Retail" itemLabel="Retail"/>
                        <apex:selectOption itemValue="Manufacturing" itemLabel="Manufacturing"/>
                        <apex:actionSupport event="onchange" reRender="showOff"/>
                    </apex:selectList>
                </apex:pageblockSectionItem>
            </apex:pageBlockSection>
            
            <apex:outputPanel id="showOff">
                {!theRecord.Industry}
            </apex:outputPanel>

        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Extension class:

 

public class testWeirdBugExtension {

    public Account theRecord {get;set;}

    public testWeirdBugExtension(ApexPages.StandardController controller) {
        theRecord = (account)controller.getRecord();
    }
}

 

 

I'm using a trigger to submit custom object records for approval as soon as they are created.  Here is the code that submits the record(s):

 

 

trigger modSubmitter on Modification__c (after Insert) { Approval.ProcessSubmitRequest[] reqs = new Approval.ProcessSubmitRequest[]{}; for(Modification__c m : Trigger.New){ if(m.Status__c!='Approved'){ Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setObjectId(m.id); reqs.add(req1); } } if(reqs.size()>0) Approval.ProcessResult[] result = Approval.process(reqs); }

 

 

 I then try inserting a record and it fails because an exception is thrown, error is "MANAGER_NOT_DEFINED".  All users involved in the process have managers defined in their user records... plus the approval process doesn't look at the manager field on any users anyhow... it just uses 'related user' lookup fields for all steps.

 

The API docs just say that this error means there is no manager for the approval process, which doesn't help much.  I scoured the Apex guides to see if there were more Approval methods available for somehow defining a "manager" for the request, but there is nothing.

 

Any ideas?

 

Check out this strange behavior I have encountered.  The basic scenario is that there is a VF page created with standard controller (for our example, Contact object) and then you extend the controller and in the extension you create an object of a different type (in this example we create an opportunity).

 

Then you add a simple form to the page to capture a lookup (in this example we'll have an input field for the Account of the Opportunity we've defined).  Lastly, create a button that will basically do nothing (just refresh the page).

 

Renders ok, but when you lookup an Account, then hit the button you get a strange "An error occurred when processing your submitted information." error message on the input field.  What is the deal?  Does anyone have any suggestions on how to make this work?

 

 

page:

 

<apex:page standardController="Contact" extensions="MyExtension"> <apex:form> <apex:inputField value="{!myOpp.Account}"/> <apex:commandButton action="doSomething" value="Do Something"/> </apex:form> </apex:page>

 

extension:

 

public class MyExtension { public Opportunity myOpp {get;set;} public MyExtension(ApexPages.StandardController controller) { myOpp = new Opportunity(); } public PageReference doSomething(){ return null; } }

 

 

 

 

 

I have noticed that when you add Parameters to a PageReference that have blank spaces, the spaces ultimately get changed to a plus sign (+) upon redirect, but I would rather use the unicode version (%20) instead because that is what the target application is expecting.

 

Anyone know a way to control this?

I have a page which does some checks and if everything looks good it redirects the user to another webpage outside of salesforce and it passes some info in the URL.  I am using the "action" property of the page which works really well for this sort of thing.  The problem is that when I define a PageReference, and then redirect the browser, the parameters are in alphabetical order instead of the order I defined them.  So for instance:

 

1.  I define a new PageReference('https://www.mycoolurl.com?Bparam=Bval&Aparam=Aval')

2.  Use action to call function which returns my PageReference

3.  Browser goes to 'https://www.mycoolurl.com?Aparam=Aval&Bparam=Bval'

 

This is not a problem with salesforce pages because it doesn't care about the order, but unfortunately the address is to an older more rigid system which I have little control over and it expects the parameters in a certain order.

 

Any way I can control the order?  I really hope so, because otherwise I am going to have to use some workaround that will involve JavaScript redirects or something, which usually leads to a lot more support issues.

I have a managed package application that includes a Document Folder with Images in it... and an S-Control that displays those images.  The installation process correctly "re-maps" the image tags in the S-Control to point to the ID that corresponds to the proper Image as it exists in the installed org.  (Which is a beautiful thing, by the way)
 
The problem is that this "re-mapping" does not happen correctly when the package is installed in a Sandbox org.  The S-control is updated with some new strange IDs that DO NOT match the IDs of the correct images in the Documents folder... thus, the images do not display.
 
Has anyone experienced this, or know why this is happening and if there is anything that can be done?
 
If anyone would like to see what I am talking about... install the following app in a Sandbox org:
I have been seeing some strange problems pop up all around our org, and they all seem to support a theory I have developed which goes like so:
 
If a user is logging in from an IP address that is NOT on the whitelist, they are asked to activate the computer.  Once the machine is activated, they can then log in and use the application.  The user, however, will not be able to correctly display / utilize s-controls which make use of the AJAX toolkit.  The soap messages are not accepted by the API and it seems that the error returned is that of 'invalid session ID'.
 
Several users have reported s-controls not working, and upon adding them to the whitelist they began to work again.  I imagine that this would be a problem experienced by many customers by now... has anyone seen problems?
I've recently been tasked to customize the clone function on Opportunities so that various additional things can happen (or not happen) such as cloning of custom child objects.  I realized that the biggest challenge here seems to be flagging an Opportunity as a clone... if you can do that, the rest is easily done with workflow or triggers.
 
So, I've done some experimentation and believe I found a way to populate a field called "Cloned From" on clones only... it is a lookup to the original opportunity.  Then use Apex to check for this after inserts, and act accordingly.
 
So my challenge to you is...  How can you detect that a record is a clone and flag it?
 
Once I'm certain my approach is solid I will post an explanation... in the meantime, I thought I would get your gears turning.
 
 

It turns out that upon request of one customer for sure (possibly more), the 500 count role limitation was lifted for their org.  I have confirmed for myself that they now have 1000+ Roles.  So, the limit was changed, but it seems that the API still thinks that 500 is the limit.  When I query for all the roles in their org, I get the following back in the result:

size                  1178

done                 true

queryLocator     null

records             [500 records are returned]

Hence there is no way for me to get back all the roles.  It seems clear that the API was not ammended to handle more than 500 roles.  Please advise. 

I've built a native application which needs Page Layout info.  You can't call describeLayout directly in Apex, so my workaround is to use a web service callout to call the SOAP API.  It works really well, BUT a few customers are unable to use the app because the call fails due to the describeLayout response being greater than the maximum response size that Apex can digest (3MB).

I have no idea why the response is so larger... the orgs in which I've investigated have a very reasonable number of fields, layouts, record types, etc.

So my questions for you experts:  What the heck is in this response that could be making it so large?  How can I work with the customer to somehow get the response size down?  Any recommendations?

I reckon this might be helpful to a lot of you. If you want to dynamically change the height of an s-control being displayed 'in-line' as part of any page layout, simply call the function below in your s-control after it has loaded (and as needed after anytime the contents of the s-control may change height). Replace ENTER_ID_HERE with the id of the s-control being run.

This same function can be used by s-controls being displayed in a web tab as well, just replace "ENTER_ID_HERE" with "itarget".

Code:
function resizeframe(){ 

sframe=top.document.getElementById("ENTER_ID_HERE"); 
sframe.style.height=document.body.clientHeight + "px";

} 
 
Hope this is found helpful.  Happy new year all.
Can anyone help me developing the Custom webservice for Data.com DunsRight Match API?

I refered to below link
https://resources.docs.salesforce.com/206/latest/en-us/sfdc/pdf/datadotcom_api_dev_guide.pdf

but I need specific detials how to pass the URL and get response? We have already implemented Data.com Match API Custom Rest Webservice. Can we use same Authorization details for developing the DunsRight Match API?

Thanks
 
  • January 31, 2017
  • Like
  • 0
So I have code that creates an event when a field is populated (on create or update). This is a way for secondary systems to trigger event creations. The logic is on create if the field isnt null, make an event with some attributes. On update, only do so if the new value differs from the old AND is not null. For some reason in my testing, it appears fine, but Ringlead (a third party tool thats populating this field) is causing double activities to create and I'm confused as to how/why.

/* 
Author: John Athitakis
Synopsis: When a new or existing Lead has a special string field populated, an event is created with that string as its subject line
*/

trigger LeadCreateEvent on Lead (after insert, after update) {
   //  Logic: On insert if the Event Activity Field is Populated, Create an Event.
 if(Trigger.IsInsert) {
 for (Lead UpdatedLead: Trigger.new) {
     if(UpdatedLead.Event_Activity_Subject__c!=null){     
            Event event=new Event(
            OwnerId = UpdatedLead.CreatedById,
            WhoId = UpdatedLead.id,
            StartDateTime = UpdatedLead.CreatedDate,
            EndDateTime = UpdatedLead.CreatedDate,
            Subject = UpdatedLead.Event_Activity_Subject__c
        );
            insert event ;
     }
 }
 }
   // Logic: On update, if there is a change in the Event Activity Field & it is not Null, Create an Event 
 if(Trigger.IsUpdate){
     for (Lead UpdatedLead2: Trigger.new) {
      Lead PriorLead = Trigger.oldMap.get(UpdatedLead2.ID);
         if (UpdatedLead2.Event_Activity_Subject__c != PriorLead.Event_Activity_Subject__c && UpdatedLead2.Event_Activity_Subject__c!=null){
            Event event2 = new Event(
            OwnerId = UpdatedLead2.CreatedById,
            WhoId = UpdatedLead2.id,
            StartDateTime = UpdatedLead2.CreatedDate,
            EndDateTime = UpdatedLead2.CreatedDate,
            Subject = UpdatedLead2.Event_Activity_Subject__c
        );
             insert event2 ;    }}
Last week, it was brought to my attention that security reviews and audits are now asking ISVs to check for Field Level Security (FLS) and Object CRUD permissions prior to any DML outside of standard controllers.  

This is a fairly radical change that impacts a lot of managed package applications across the board. I and others have several concerns about this change in the security review process:
  1. Why the sudden change in security review policy?  
    • None of the ISVs I have talked to were informed of the change prior to being either audited or submitting any apps for security review.  The only official documentation I can find on the change is a blurb in the Security Scanner help page here: http://security.force.com/security/tools/forcecom/scannerhelp.  
    • As ISVs, it would be greatly appreciated to have an official Security Review Guide, that is updated well in advance to when policy changes like this take place.  Some ISVs have several packages, others lots of customizations, and we all need time to prepare for the security review.
  2. Has the security scanner been updated to enforce this rule yet?
    1. I have not run an app through the Security Review process recently, so I am curious if this rule has been implemented already in the security scanner. (http://security.force.com/security/tools/forcecom/scanner)
  3. Why force FLS and CRUD checks on every DML transaction?
    • I am a fan of using standard controllers when necessary, but several apps, including one my company develops rely heavily on Custom Controllers.  In most cases where FLS comes into play, typically it's a simple fix of a profile permission or permission set that resolves the issue.  Instead, now, we have to implement FLS and CRUD checking prior to each DML transaction.  This adds complexity on top of existing DML calls.  
    • If need be, can the FLS and CRUD checking be done on a one-time run in an install script?
    • Does Salesforce have any plans of either adding FLS checking for custom controllers or adding methods to Apex for checking credentials similar to the Force.com EASPI library? (https://code.google.com/p/force-dot-com-esapi/)
Thanks, I look forward to hearing any feedback on this issue.

Hey folks. I'm writing a Visualforce page that will act as a custom console component in the Service Cloud Console, and I'm seeing some odd behavior when using apex:outputLink. Net-net: the outputLink tag intelligently renders differently when in the console vs outside the console (fantastic) but for some reason, the Javascript function it calls when operating *in* the console cannot be found...even if I import the Console Integration Toolkit.

 

Here's the VF page in question:

<apex:page standardController="Case" extensions="MyExt" showHeader="false" sidebar="false">
<script src="/support/console/28.0/integration.js" type="text/javascript"></script>
 <apex:pageBlock rendered="{!initiated}" title="Users">
  <apex:pageBlockTable value="{!portalUsers}" var="user">
   <apex:column title="Username">
    <apex:outputLink value="/{!user.Id}">{!user.Username}</apex:outputLink>
   </apex:column>
   <apex:column title="Name" value="{!user.Name}"/>
  </apex:pageBlockTable>
 </apex:pageBlock>
</apex:page>

 

Even when including the console toolkit js file (using both manual <script> tags and <apex:includeScript>) I get the following error when clicking on the rendered link in the console:

Timestamp: 6/23/13 6:31:29 PM
Error: ReferenceError: srcUp is not defined
Source File: javascript&colon;srcUp('%2F005i0000000poJdAAI%3Fisdtp%3Dvw');
Line: 1

 Any thoughts on what I may be missing?

 

 

 

 

 

I thought this error was a thing of the past when Salesforce put out a fix for resolving Visualforce session Ids several years ago but it's apparently hard to kill.  Here are the facts:

 

The error is happening when using the session Id from the global API variable with the AJAX toolkit (see code below)

The Visualforce Page in question is part of a managed package

The customer hitting the error is doing so in a sandbox, Unlimited Edition

This app is working correctly for hundreds of other customers without a problem

The "lock session to originating IP" setting is turned OFF

Viewing Source on page confirms that a session Id is being populated on this line of the JS

 

For whatever reason this customer is getting "Invalid Session Id".  I could begin the "shots in the dark" and try going back to old school tactics like getting the session Id from the Apex controller instead of a merge field... but why is it working for all other customers and not this one?  Also, I don't want to do too much trial and error because its a huge PITA to uninstall in their sandbox, reupload a beta package, an reinstall for every little thing I want to try and test.

 

Any ideas?

 

<script src="../../soap/ajax/24.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">
    
        sforce.connection.sessionId = '{!$Api.Session_ID}';

</script>

 

I scoured the message boards and don't see anyone else who has run into this.  I'm thinking it's a bug, although not a terribly detrimental one.

 

I have a "without sharing" class that needs to know if the current user has access to a list of records.  So it uses a separate "with sharing" class to figure it out... works well.  Then to take it one step further and see if they have access to edit you have to get creative, and the knowledge in this forum told me the only way is to attempt an update, see which records failed and then do a rollback to a savepoint... this too works well, woohoo.

 

The weird thing, is that the records that are updated in this check will then show up in the users recent items.  I could see how maybe this is a good thing if the records were actually updated... but they weren't the change was rolled back.  I guess it's a bug.. thoughts?

I'm not sure if this is expected behavior or a bug, or if there is something I'm missing.

 

As of Winter '11, InputField components will load on your page with the default value for the corresponding field.  Very cool, and it even works for Dynamic Visualforce too.  But I've noticed that it will only work if the field is included at the time the page is loaded.

 

So if you have anything dynamic going on that causes an inputField to be added to the page such as an action runs and "reRenders" a section causing a new inputField to be rendered within... or if you use Dynamic Visualforce and your controller passes back an inputField that wasn't previously included in the dynamicComponent.  The newly added InputField will be empty, any default value is ignored.

 

I've even tried to be sneaky and use a wizard approach so that the controller can do some calculating and initalization and interaction with some AJAX on the first page and then when it is ready to display my inputFields it forwards to another page with the same controller.  So the controller and all data remains, but the user is on a fresh page that will display the input form... this didn't work.  So it's clear that the inputField will only have the default if it is part of the page when BOTH the page AND controller (and/or extensions) load.

 

Bug?  Or is this how it should be?

 

Of course if the field describe result "getDefaultValue()" method actually did what the name implies then I could just fetch it myself :-)

 

 

Hey folks,

 

I have some Visualforce pages in a managed package that I would like to expose to ALL users in an org (ALL meaning those with a license to my app and those who do not) and based on whether they have a license or not it will act differently.

 

At first glance I thought, hey cool they have a function for exactly that... I can call UserInfo.isCurrentUserLicensed('myApp') to find out and act accordingly.

 

Upon further thought, I realized that no code from the package can ever be run by unlicensed users in the first place, so there is no way to perform such a check... am I missing something?  Or is this method not able to be used from within a managed package?

 

You can use it in your own code to see if a user has a license to something else you've installed... or one partner app could use it to see if you have their competitors product installed (LOL) but nether of those seem all that helpful.  Any idea what this method is good for?

 

In case you are wondering, this is another thread that explains what I am trying to accomplish which lead me to wonder about this method:  http://boards.developerforce.com/t5/Visualforce-Development/Action-Override-to-Managed-VF-page-breaks-other-users/m-p/442317#M50598

Hey folks, I've been playing with Dynamic Visualforce pretty heavily lately.  I noticed something funny and wanted to see if it is "normal" / expected behavior or not.  The deal is, when you have a dynamicComponent on the page and you reRender another part of the page (a section that doesn't contain the dynamicComponent) the get method for the dynamicComponent is still running again.

 

Below is an elementary example.  We have a dynamicComponent whose get method will return an empty PageBlock and has a debug statement to make it clear when that get method runs.  Then below that is a section with a button inside it that will reRender when the button is pushed without reloading the page (i.e. return type is void, not PageReference).

 

When you click the button and check the debug log for that button push, you will see that the "getTheBlock" method ran even though the dynamicComponent wasn't "supposed" to be reRendered.  Puzzling!

 

Page:

 

<apex:page controller="troubleController">
    <apex:form >

        <apex:dynamicComponent componentValue="{!theBlock}"/>
    
        <apex:outputPanel id="mySection">
            <apex:commandButton value="reRender below value" action="{!someAction}" reRender="mySection"/>
            <br/>{!now()}
        </apex:outputPanel>

    </apex:form>
</apex:page>

 Controller:

public with sharing class troubleController {

    public void someAction(){}

    public Component.Apex.PageBlock getTheBlock() {
    
        system.debug('The block is being got!');
    
        Component.Apex.PageBlock block = new Component.Apex.PageBlock();
        return block;
    }
}

 

I am using the LMA and want to know if it is possible to programmaticaly tell if a user has been licensed for my package. 

 

Imagine if I wanted users of the application to see each other's application specific data - at minimum I would need a list of users that are licensed to use the application.

 

Is this possible? I want to be able to add code to the package that can be used to make decisions based on whether users have been granted a license seat through the LMA's "Manage Licesnes" process.

Hey folks, I'm in a new role now, so I will be coding a lot more.  Looking forward to hanging out in here more often!

 

I'm working with Dynamic Visualforce at the moment (apex:dynamicComponent) to build a simple Lead form.  It's a long story why it has to be built dyamically.  I'm extending the standard Lead controller, and leveraging the standard {!save} method.  It works great when the record saves... they are brought to the new record and all the info they entered is there... woohoo!

 

The problem is when they click save but haven't filled in one or more required fields.  The form refreshes and correctly identifies the fields they forgot to populate and notifies them as is appropriate.  BUT, all the info they had entered is cleared out!

 

Here is a small example that shows what I mean:

 

Visualforce Page:

<apex:page extensions="dynamicTestController" standardController="Lead">

    <apex:messages />

    <apex:form >
        <apex:pageBlock mode="edit">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            
            <apex:dynamicComponent componentValue="{!mySection}"/>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Apex Controller:

public with sharing class dynamicTestController {

    public Lead theLead {get;set;}

    public dynamicTestController(ApexPages.StandardController controller) {
        theLead = (lead)controller.getRecord();
    }

    public Component.Apex.PageBlockSection getMySection() {
        
        Component.Apex.PageBlockSection section = new Component.Apex.PageBlockSection(columns=1);
        
        Component.Apex.InputField field1 = new Component.Apex.InputField();
        field1.expressions.value = '{!theLead.LastName}';
        
        Component.Apex.InputField field2 = new Component.Apex.InputField();
        field2.expressions.value = '{!theLead.Company}';
        
        Component.Apex.InputField field3 = new Component.Apex.InputField();
        field3.expressions.value = '{!theLead.Phone}';
        
        section.childComponents.add(field1);
        section.childComponents.add(field2);
        section.childComponents.add(field3);
        
        return section;
    }
}

 

 

 

You can see that when you populate LastName and Phone, but NOT Company and click save the form is cleared out... not cool!

 

I've concocted a workaround, which is to use a custom save method that returns nothing so I can avoid refreshing of the form.  I then use the apex:messages component to display any errors at the top of the page and redirect with JavaScript if there are no errors.  It works, but then errors that should be on a specific field are at the top instead and I would rather not have to rely on JS for navigation like that.

 

Any thoughts?

 

Cheers,

michaelforce

Recently, I was writing some classes that needed to detect if the org they were in was a sandbox or not and determine which endpoint to call accordingly. Since there isn's an isSandbox method in Apex, I had to create my own. This will work in visualforce controllers/extensions and from standard classes. You can read the full details at http://www.ericsantiago.com/eric_santiago/2011/12/determining-salesforce-server-pod-and-if-sandbox-via-apex.html

 

Code as follows

 

public String currentPod { 
            String server;
            
            if (ApexPages.currentPage() != null){ //called from VF page
            		server = ApexPages.currentPage().getHeaders().get('X-Salesforce-Forwarded-To');
            } else { //called via standard class
            		server = URL.getSalesforceBaseUrl().getHost();
            }
            
            if ( server != null && server.length() > 0){
                server = server.substring(0 ,server.indexOf('.'));
                
            }
            return server ; 
   }

   public Boolean isSandbox {
            String pod = currentPod();
            if (pod != null && pod.length() > 0 && pod.toUpperCase().startsWith('C')){
                return true;
            }
            return false;
   }

 

Is there a way for the code to know whether or not it is running in a production instance, or a sandbox?

 

I have scheduled APEX that sends an email to specific email addresses three times a day.  Whenever someone makes a new sandbox in our company, that sandbox starts sending the emails and I have to manually go into every sandbox when it is created and remove the scheduled APEX.  I want the function to be smart enough to know that it is running with a sandbox environment, and therefore not send the email.

 

Any ideas?  

 

Thanks!

Paul

Hi,

 

Is there a way to detect in Apex if the system is a Sandbox or a Dev Edition?

 

Thanks.

 

 

 

 

We're experiencing an issue that I don't see a good solution to. We have a managed package installed, and only some users have a license to the package. We've overriden the New button for the Campaign object with a VisualForce page from the aforementioned package. This override works grea for users with a license.


The problem is that if an unlicensed user tries to create a new campaign, they get a "License Required" page, and cannot create campaigns.

 

Ideally, the system would just redirect the unlicensed users to the standard create page, equivilant to adding nooverride=1 to the URL.

 

Any ideas?

  • March 16, 2010
  • Like
  • 0
Is it possible to determine whether the current user has delete permissions (aka Full Access) for a particular record (custom object), without actually attempting to delete the record?

I'm creating some custom actions using VF/apex, and for some of them I want to limit who can perform the action to the same users who can delete the record.  The action does not involve deleting the record, but I want it to be more restrictive than who can perform an edit.

I looked into the sharing table (object_share) but that only lists the owner as Full Access.  Since anyone above the owner in the role hierarchy also has full access, and the hierarchy might be several levels tall, it seems like a tall order for my code to walk the entire hierarchy and determine if that applies.  Is there an easier way?

Thanks much!
  • August 04, 2008
  • Like
  • 0
Is it possible to replace the ui/opportunity/SelectSearch with a visualforce page ?
 
any idea ?
 
 
  • July 23, 2008
  • Like
  • 0