• garyb
  • NEWBIE
  • 235 Points
  • Member since 2008

  • Chatter
    Feed
  • 7
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 71
    Replies

USE CASE: I've queried a record from an object that contains a multiselect picklist field (Region__c):


Employee__c bsc = [SELECT id, Division__c, Region__c , User__c FROM Employee__c
WHERE User__c = :UserInfo.getUserId()];


Now, I want to pull all of the selected values of that Multiselect picklist field into a String[], so I can use that in another query.

The following query doens't work because bsc.Region__c is not a string -- but how can I query to see if Order__c.State__c is a member of bsc.Region__c?

oldestOrder = [SELECT id FROM Order__c
WHERE OwnerId = :q.QueueId AND
Status__c NOT IN :ignoreStatus AND
State__c IN :bsc.Region__c
ORDER BY First_Submit_Date__c

LIMIT 500][0].id;

How to turn on Delegated Authentication (SSO) for user ?

Hi ,

 

I have a custom object in which I save the record type (it can be accounts, contacts, leads).

Here is my code

 

 

String obj='Contacts'; 
RecordType rt = [select id, name from recordtype where name =: obj limit 1];
System.Debug(rt.name); //Gives Contacts
savedGrp.RecordType = rt;
insert savedGrp;  

it always saves accounts...

 

 

 

 

Please help me with this.

 

Thanks

Hector.

Hi,

 

I created an "after insert" trigger on Account, which is not getting the complete record set when i bulk insert the records. 

 

I tried to insert 1000 Acocunts using data loader with batch size of 200 and placed a single statement in my trigger (just for test) i.e. System.debug(Trigger.new.size()). All my 1000 accounts are created, but when i see the logs , trigger has been executed for 5 times but everytime it recieved only 100 records i.e. total of 500 records.

 

Can anyone explain why is it missing records.

 

Thanks,

Gulshan

  • February 05, 2009
  • Like
  • 0
What is difference between Trigger.new and Trigger.newMap? The Apex Guide doesn't quite elaborate enough to make it clear.

Thanks,
Luke

Hi all,

 

I have the following code:

 

trigger ContentVersion on ContentVersion (after insert) {
  HelperClass.doStuff(Trigger.newMap.keySet());
}

public class HelperClass {
  @future
  public static void doStuff(Set<ID> recordIDs) {
    System.debug('recordIDs : + ' recordIDs);
    List<ContentVersion> content = [select ID from ContentVersion where ID in :recordIDs];
    System.debug('content : ' + content);
  }

}

 

A trigger that calls a future method, passes in the IDs of the record in the operation, and then retrieves those records from the database. Here's what happens:

 

The first debug statement shows that the recordIDs variable has a value

The second debug statement shows that the content is NOT retrieved - the list is empty.

 

Has anyone else seen this? Am I doing something wrong?

  • May 16, 2012
  • Like
  • 0

Has anyone else had issues with using apex:variable, apex:repeat, dynamic fields, and state not being preserved when actions take place?

 

I've got the following PoC, a page and its controller. The page shows the First Name and Last Name of a contact (hard coded ID - replace it with one of your own if you're trying this at home) as inputfields. The user can make changes and click a button and the changes should save. However, they do not.

 

First the page:

 

<apex:page tabStyle="Contact" controller="TestingPageCtrl">
    <div style="margin-top:14px">
        <apex:form >
                <apex:variable var="obj" value="{!sobj}"/>
                <apex:variable var="fieldNames" value="{!fields}"/>
                <apex:pageblock>
                    <apex:pageBlockSection>
                        <apex:repeat var="fieldName" value="{!fieldNames}">    
                            <apex:inputField value="{!obj[fieldName]}"/>
                        </apex:repeat>
                    </apex:pageBlockSection>
                </apex:pageBlock>

            <div style="width:610px">
                <apex:commandButton value="Next" style="float:right;" action="{!save}" />
            </div>
        </apex:form>
    </div>
</apex:page>

 

And now, the controller:

 

public class TestingPageCtrl {

    public SObject sobj {get; set;}
    public List<String> fields {get; set;}
    
    public TestingPageCtrl() {
        System.debug('In TestingPageCtrl');
        sobj = [select ID, FirstName, LastName from Contact where ID = '003K0000009T2za'][0];
        fields = new List<String> {'FirstName', 'LastName'};
    }

    public PageReference save() {
        System.debug('In save()');
        Database.update(sobj);
        return null;
    }
}

 

In the save() method, the changes made by the user are not carried across. There are some things I've noticed:

 

  • I actually first encountered this in a custom component. Using attributes (and passing the values in from the parent page) rather than variables works - however, there is some loss of elegance in the code.
  • You'll notice I'm using a repeat to loop over strings that are field names, and they are then used with dynamic bindings so that the controller can control what fields are displayed. Removing this repeat and putting hardcoded dynamic bindings (i.e. obj['FirstName']) works. Problem here is that my code becomes a lot less re-usable.
  • Looking at the debug logs, it looks as if the deserialization is not being performed when the action takes place.

 

I don't understand why this doesn't work as it is - is there something I'm missing or doing wrong? Do people think this should work as it currently it?

 

Any feedback and input would be greatly appreciated!

 

P.S. - I'm pretty sure this is not Summer '12 related as I was having this issue on Friday night before (and after) the upgrade.

  • May 14, 2012
  • Like
  • 0

Hi all,

 

I've posted before on Twitter about the browser-based developer console, and hinted at some of the issues I've had (overall though, I do like it), but not put them down in any meaningful fashion.

 

One of my dev orgs was updated to summer 12 this weekend and I've encountered an issue that's a real nusiance, so it's prompted me to post here to explain it in full. I'll also use this thread to list some of the other issues/areas for improvement.

 

Anyway, the main issue I'm having at the moment: before the update, the console was pretty good at working out when I had done something stupid and preventing the save, which allowed me to fix and save again once correct. After the update however, I get notified of the problem after I try to save, and worse, when I make changes, I can't save the file. I have to close the developer console window and open it again, re-do my changes and then save.

 

Previously I think this is how it worked:

  1. User made changes to code in the console
  2. As user made changes, either javascript on the page ran checks on the code, or sent the changes to the server - but did not commit them
  3. When the user clicked save, the file was committed. The user could only save if the console thought the code was valid i.e. if the code passed step 2.

 

Now, it's as if the following is happening:

  1. User makes changes to code in the console.
  2. User clicks save - it is only at this point that the code goes to the server.
  3. If there are errors in the code, the user is told there is an error. Internally, the console notes the code is invalid because the server has told it so.
  4. User fixes the error, but cannot save the code as the console believes the code is invalid, because the server told it. The console should try to save the file again and await the new result.

 

Hope that makes sense - any one else experiencing the same? I'm using Chrome, haven't tried other browsers as yet.

 

Other issues I've been meaning to post about:

 

  • No asterix on tab names - OK, this is a Summer 12 change. Previously, when you had multiple files open in the console, ones you'd changed but not saved were shown with an asterix against their name in the tab. This was useful but has been removed.
  • Refresh - Every now and again you'll get a message about having to refresh logs manually, even when there are no logs open. You get one of these messages for every class/page you have open.
  • Attribute suggestions - The editor can be a bit keen to suggest attributes for VF tags as you move around code. Actually this looks like it may have been fixed :)

 

Those are the only ones I spring to mind right now. I'll bookmark this thread and add more as I think of them.

 

I don't want to sound overly negative about the developer console - niggles aside, I was really quite happy with the last release's version, so much so that I made it my first choice for development over the Force.com IDE, and I really like the look of some of the things in the latest release. And it's all a long, long way away from the options we had, even as little as a year ago, so please keep up the great work :)

 

  • May 14, 2012
  • Like
  • 0

Hi all,

 

I have some batch apex. I start a batch and going by the debug logs, it looks like everything is running smoothly - no errors occur in the logs, and their statuses are 'Success'.

 

However, monitoring the Apex Jobs page, the job shows up once started, however, a few batches in, the status detail updates to "First error: Attempt to de-reference a null object". And that's all - there's no log an no clue as to where this problem is actually occuring. Looking through the debug logs, there's nothing there that shows an exception

 

I'm not perfect, it's perfectly possible I have a line of code doing something silly at a certain point - but any ideas how I can find out where I'm going wrong?

  • August 04, 2011
  • Like
  • 0

Hi all,

 

We've implemented federated SSO with SAML 2.0 and identity provider initiated login is working as it should. However, we're seeing an issue with service provider initiated login.

 

This happens when a user tries to visit a specific salesforce page such as https://cs3.salesforce.com/home/home.jsp and is not authenticated (for example, they have logged out). If the user has used identity provider initiated login, they have a cookie stored on their machine and rather than being shown the salesforce login screen, the browser is redirected to the identity provider (and back to salesforce once authenticated).

 

This works as expected in Chrome and Firefox. Internet Explorer works for the most part, but there's one annoying wrinkle. If the user uses the "Log out" link in Salesforce and once logged out, tries to access a specific salesforce page (such as the home page link above) within the same tab, the user sees the "You are now logged out" screen and is returned to a salesforce login screen.

 

If the user tries to access the page in a new tab (or closes & reopens the browser), the problem does not occur.

 

Has anyone else seen this and if so, could you share ways of dealing with the issue?

 

Thanks in advance!

  • May 04, 2011
  • Like
  • 0

Hi,

 

We want to use delegated authentication so that mobile users can access Salesforce mobile apps without entering usernames and passwords. We're looking to use username and passwords (rather than username & token).

 

When using delegated auth for desktops, you can (for example) provide a link on an intranet page for users that will take the user to a page that passes the user's username and password to salesforce.com in a POST request. That user has a delegated auth enabled profile, so salesforce.com passes the credentials to a delegated authentication authority.

 

That part I'm clear on!

 

What I want to know is - how does this work for mobile application users? If a user downloads Salesforce.com Mobile they need to identify to the application what their username and password is. But if a user is SSO enabled, this will mean nothing to them.

 

So how does a user identify who they are? Is this method reliant on users entering their email address as their username (and therefore it is implicit that their username will be the same as their email address) and their network password as their salesforce.com password? Or does the mobile need to be routed through a proxy that will pick up the attempt to visit the login page and construct the necessary POST request instead?

 

Any input appreciated, especially from anyone with experience of doing this!

 

  • March 25, 2011
  • Like
  • 0

You have an object with a picklist that contains three values, x, y and z. For testing purposes, you create a record of that object type with a value of "a" in the picklist - Apex allows you to do this. There are already records in the database withvalues of x, y or z in the picklist.

 

You then have a query (after the test has created the record with the "a" value in the picklist) that runs like this:

 

 

Some_Object__c so = [select ID from Some_Object__c order by Your_Picklist_field__c asc nulls last limit 1];

 

 

Which record is returned from the database? The one with "a"? No - for some reason this is the last record returned by the query.

 

Can anyone else confirm this, and if there's anything obvious I'm missing to get what I think should be the expected result - the value inserted by the test is the returned record?

  • October 29, 2010
  • Like
  • 0

Hi all,

 

We're gearing up on a project with Customer Portal users (with profiles derived from the "Overage Customer Portal Manager Standard" profile). We're trying to enable Customer Portal users from Person Accounts/Contacts and this works if the user who is enabling the Customer Portal User owns the account. If they don't own the account however, we're getting an "Insufficient Priviliges" message.

 

The profile of the internal user has the "Edit self-service users" permission and from what I can see in the help, this should be sufficient. If we change the owner of the Account to the user trying to enable the contact, it works.

 

Has anyone encountered this before? We suspect it's something to do with the role for the Customer Portal User - Salesforce wants to prepend the alias of the account owning user to the role, however, this is different from the user trying to enable the contact.

 

Appreciate any help!

 

  • September 08, 2010
  • Like
  • 0

Hopefully an easy one...

 

If I use Dataloader to insert new records and the object I'm inserting has an autonumber field, is there Salesforce magic to prevent an autonumber being used twice in the separate sessions? Something like:

 

1. Session A begins first batch of insert

2. Session B begins first batch ofinsert

3 .Session A finishes first batch ofinsert

4 .Session B finishes first batch ofinsert

 

Between 2 and 3, will an autonumber used in Session A ever occur in Session B?

 

Thanks in advance...

  • August 04, 2010
  • Like
  • 0

Would like to hear other people's opinions on this thorn in my side...

 

I'm trying to tidy up some parts of the application I'm developing by limiting the impact of (for example) ID changes between environments. In a Java environment, you could hold this sort of information in .conf files.

 

For example, let's say I have a VF page that contains links to certain list views. These list views are not likely to have the same ID in my Dev org as my Production org. How best to manage this? Hold it in a static variable in one place in code? Downside there is I have to update the code with the values for Production before I deploy. What about a custom setting? Custom Setting objects are deployable, but the records are not so I'd have to import data into the production org first, and makes deployment more complicated. 

 

What are people's best practices/workarounds for this sort of situation? The above is just an example rather than a specific problem (though if there is an elegant solution to that problem, I'd love to hear it).

  • July 29, 2010
  • Like
  • 0

Hi all,

 

I have some code that looks at CaseTeamTemplates and behaves differently depending on those CaseTeamTemplates. I'm trying to test the code but to do that I need to insert some CTTs. However, I can't do that and then insert, for example, Cases as I get a MIXED_DML_OPERATION error - basically, I can't insert setup objects and non-setup objects in the same test. So.... how can I give my code the necessary test coverage?

 

Anybody encountered this before and managed to work around it?

  • July 26, 2010
  • Like
  • 0

We have a formula field on Account that displays the record type as text - it's not really for end user consumption (looking at a record will display the record type anyway) but to make life easier elsewhere. The formula is: $RecordType.Name

 

On a Case, we are trying to use the value of this field in another formula field. To make it easy, imagine we have a formula field on Case called "Account Record Type" - it's a formula that is essentially: Account.My_Custom_RecordType_Formula_Field__c

 

The problem is the value in the "Account Record Type" field on the Case is showing the Case's record type, not the account record type. It's almost as if the account field formula is being evaluated on the Case.

 

Is this standard behaviour? Any explanations? Thanks in advance, and sorry if this means I flunk config 101 :)

  • July 07, 2010
  • Like
  • 0

Hi all, hopefully a straightforward one!

 

I want to retrieve cases where the user is the owner and the user is also a case team member. I'm trying to do something like:

 

Select ID From Case where OwnerID = 'someUserID' and OwnerID in (select MemberID from CaseTeamMember)

 

I'm running this in the Force.com IDE and I'm getting the following message:

 

"The selected field 'MemberID' in the subquery and the left operand field in the where expression in the outer query 'OwnerID' should point to the same object type."

 

MemberID can be a reference to a Contact or a User, whereas OwnerID can be a reference to a Group or a User - I suspect this is what's causing the problem?

 

Any advice gratefully received :)

 

 

  • May 14, 2010
  • Like
  • 0

Hi all,

 

I've got a field on a Visualforce page that has changed from a picklist to a look up. I have standardStyleSheets="false" in the page tag. I have an inputfield that binds to the look up on the object that I want to populate. I've tried a number of things but I can't get the lookup button that appears next to a lookup field to display.

 

If I change standardStylesheets to true, it will appear - but the rest of my page breaks.

 

Any ideas on how to fix this?

  • May 12, 2010
  • Like
  • 0

I'm currently trying to wrap my head around actionRegions. From what I've read, something like the following should work:

 

 

<apex:inputField id="field1" value="{!myAccount.SomeField}" required="true" />
<apex:actionRegion>
<apex:inputField id="field2" value="{!myOpp.SomeOtherField}"/>
<apex:commandButton action="{!doSomething}" value="Button Label"/>
</apex:actionRegion>

 

 

However, on clicking the button, I get a complaint that the first input field requires a value.

 

Obviously, the above is not my real code, and there may be problems because of something else on my page - but the above should work shouldn't it? Or have I misunderstood about action regions?

 

Thanks in advance...

  • April 28, 2010
  • Like
  • 0

Apologies in advance for the lengthy post, but if you can help, I'd be massively grateful!

 

I'm trying to build a number of forms (each on its own page) in Visualforce that are made up of sections that I want to have implemented as components, as some sections are reused across multiple forms.

For the sake of discussion, this page is split into two parts, "Top" and "Bottom". In Top are radio buttons that control what is displayed in Bottom. In Bottom is another set of radio butttons that control what is displayed beneath the radio buttons. Here's the Visualforce for a page, let's call it TestComponentUse:

 

 

<apex:page controller="APageController" showHeader="false">
    <apex:outputPanel id="TopPanel">
        <apex:form >
            <apex:selectRadio value="{!topRadio}" layout="pageDirection" >
                <apex:selectOptions value="{!topRadioOptions}" />
                <apex:actionSupport event="onclick" rerender="BottomPanel" />
            </apex:selectRadio>
        </apex:form>
    </apex:outputPanel> <!-- End TopPanel-->
    
    <apex:outputPanel id="BottomPanel">
        <apex:outputPanel rendered="{!topRadio == 'option1'}">
            <apex:form id="paymentForm">
                <c:mycustomcomponent></c:mycustomcomponent>
            </apex:form>
        </apex:outputPanel>
        <apex:outputPanel rendered="{!topRadio == 'option2'}">
            Other Content
        </apex:outputPanel>
    </apex:outputPanel>
</apex:page>

 

And the controller for the page:

 

 

public class APageController {
    public String topRadio {get; set;}
    public List<SelectOption> topRadioOptions {get; set;}

    public APageController() {
        topRadioOptions = new List<SelectOption>();
        topRadioOptions.add(new SelectOption('option1', 'Option 1'));
        topRadioOptions.add(new SelectOption('option2','Option 2'));
        topRadio = 'option1';
    }
}

 

 

The component mark up (called myCustomComponent, and used in the page above):

 

 

<apex:component controller="MyCustomComponentController">                    
    <apex:actionRegion >
        <apex:selectRadio value="{!bottomRadio}"  layout="pageDirection" >
              <apex:selectOptions value="{!bottomRadioOptions}" />
              <apex:actionSupport event="onclick" rerender="belowBottomRadio"/>
        </apex:selectRadio>
    </apex:actionRegion>
    
    <apex:outputPanel id="belowBottomRadio">

        <apex:outputPanel rendered="{!panelARendered}" id="bottomPanelA">
        Content A   
        </apex:outputPanel> <!-- End panelA -->
                         
        <apex:outputPanel rendered="{!panelBRendered}" id="bottomPanelB">
        Content B
        </apex:outputPanel> <!-- End panelB -->
    </apex:outputPanel> <!-- End belowBottomRadio -->
</apex:component>

 

 

And the controller for the component:

 

 

public class MyCustomComponentController {
    public String bottomRadio {get; set;}
    public List<SelectOption> bottomRadioOptions{get;set;}
    public Boolean panelARendered {get{return bottomRadio == 'optionA';} set;}
    public Boolean panelBRendered {get{return bottomRadio == 'optionB';} set;}
    
    public MyCustomComponentController() {
        bottomRadioOptions = new List<SelectOption>();
        bottomRadioOptions.add(new SelectOption('optionA', 'Option A'));
        bottomRadioOptions .add(new SelectOption('optionB', 'Option B'));
        bottomRadio = 'optionA';
    }
}

 

 

So, loading the page in a browser, selecting from the radio button in the top of the page, the bottom part changes as needed. Option 1 shows the two radio button labelled A and B and "content A"; selecting Option 2 shows "Other Content" in place of the bottom set of radio buttons. That part works OK!

 

However, when option 1 is selected and the second set of radio buttons are shown (Options A and B), selecting the radio buttons doesn't change the content beneath that bottom set of radio buttons. For some reason the rerender doesn't seem to be working. If you select Option B, then Option 2 then back to Option 1, then the correct content is displayed, however it does not dynamically rerender as I believe it should.

 

I'm sure I'm misunderstanding /something/ that I'm using, so what am I doing wrong?

 

Many, many thanks in advance...

 

  • April 16, 2010
  • Like
  • 0

Hi all, been banging my head against a brick wall all day with this one!

 

I'm trying to deploy reports between two sandboxes using the Eclipse Force.com IDE - however, when selecting the components, the reports are greyed out with a "No Action" assigned to the. When you click on one, the message that appears is:

 

"Dependent component, parent or metadata, is not deployable"

 

To me this reads as if there's an unmet dependency somewhere - I welcome other ideas on this!

 

When I set up the project in Eclipse (using 15.0.2 of the plugin), I pulled in all the project's components using the "Manually select the components" option. I'm trying to deploy from the root src folder, so if there was a deployable component I could deploy to satisfy the dependency, I would imagine the report would appear as deployable. However, it stubbornly stays in the "No Action" state!

 

I'd welcome any solutions, ideas, or even just a simple "This is happening to me too!" just to keep me sane...

 

TIA!

 

  • May 18, 2009
  • Like
  • 0

Hi all,

 

Is anyone else out there trying to get their head around the changes made to workflow and roll up summary field evaluations updated made in Spring 09?

 

From what I can understand, it's just the evaluation of workflow and RUS fields that are affected - triggers may still run multiple times. The reason I ask is that we have some code that will perform some actions, after which the workflow will fire and we may need to perform more actions depending on changes made by the workflow. From my understanding, this has not been broken. What are other people's opinions? Have I misunderstood?

 

There's a example (currently) given on page 82 of the spring 09 release notes. I think something was missed out of the example - the apex trigger that creates the opportunity has some logic so that it only creates one and only one opportunity (for example, some sort of static variable). Otherwise, I'm unsure why, when the roll up summary increases, another opportunity is not created. From my testing, the trigger will fire again but not the workflow (which seems to be the thrust of this update).

 

That should be enough to get the ball rolling... Thanks in advance for your help!

  • April 08, 2009
  • Like
  • 0
All,

I've noticed that when setting Dataloader's batch size option to 200, triggers are operating in batches of 100. This is not a problem in itself, but I've also noticed that static variables are not cleared between the 100 batch runs. I've included a short example below, but basically all I'd like to know is:

Why are the Dataloader batches broken up, and when does this happen?
Should the static variables be cleared automatically?

As I say, here's a quick example; it's a trigger on Contact and a class with a static variable:

Code:
public class quickClass {
    public static boolean lock = false;
}
 

trigger quick on Contact (before insert) { 
    System.debug('lock: ' + quickClass.lock);
    quickClass.lock = true;
    System.debug('Trigger.new.size(): ' + Trigger.new.size());
 
}

When we insert, say, 150 Contacts, using Dataloader with a batch size of 200 in the log file we will see:

Code:
lock: false
Trigger.new.size(): 100
lock: true
Trigger.new.size(): 50

It doesn't look like it's Dataloader fault - it does look like it's sending 150 Contacts, rather than 100 and then 50.

Like I say, I don't mind the process being broken up, but obviously I'd also like the static variables to be cleared between the processing of the first 100 records finishing, and the processing of the next 50 records starting, as we are using static variables to control execution flow. If these variables are keeping their value, it causes a problem for us!

Hope that's enough detail, thanks in advance for any help...
Gary


  • December 05, 2008
  • Like
  • 1
Hi all,

I have a set up where Object A is a parent of Object B. There is a trigger on delete of an Object B record to delete a record of type Object C related to the Object B record being deleted (ideally, Object C would be a child of B, but we can't do this unfortunately).

So: A is a parent of B, C is related to B but not via a parent/child relationship. And a trigger on B deletes the relevant C object when B is deleted.

If we delete a record of type A, it will delete B (because of the parent/child relationship) and - what I would expect anyway - the trigger on B will delete the relevant C object.

Except that it doesn't. Should it? I opened a clean developer account, put a trigger on B that just prints a debug statement, created the relevant data, deleted A and - nothing in the log.

FWIW, A is the standard Account object, B is the standard Event object, and C is a custom object we've developed.

Thanks in advance for your help!
  • October 29, 2008
  • Like
  • 0
All,

I've noticed that when setting Dataloader's batch size option to 200, triggers are operating in batches of 100. This is not a problem in itself, but I've also noticed that static variables are not cleared between the 100 batch runs. I've included a short example below, but basically all I'd like to know is:

Why are the Dataloader batches broken up, and when does this happen?
Should the static variables be cleared automatically?

As I say, here's a quick example; it's a trigger on Contact and a class with a static variable:

Code:
public class quickClass {
    public static boolean lock = false;
}
 

trigger quick on Contact (before insert) { 
    System.debug('lock: ' + quickClass.lock);
    quickClass.lock = true;
    System.debug('Trigger.new.size(): ' + Trigger.new.size());
 
}

When we insert, say, 150 Contacts, using Dataloader with a batch size of 200 in the log file we will see:

Code:
lock: false
Trigger.new.size(): 100
lock: true
Trigger.new.size(): 50

It doesn't look like it's Dataloader fault - it does look like it's sending 150 Contacts, rather than 100 and then 50.

Like I say, I don't mind the process being broken up, but obviously I'd also like the static variables to be cleared between the processing of the first 100 records finishing, and the processing of the next 50 records starting, as we are using static variables to control execution flow. If these variables are keeping their value, it causes a problem for us!

Hope that's enough detail, thanks in advance for any help...
Gary


  • December 05, 2008
  • Like
  • 1

Hi all,

 

I have the following code:

 

trigger ContentVersion on ContentVersion (after insert) {
  HelperClass.doStuff(Trigger.newMap.keySet());
}

public class HelperClass {
  @future
  public static void doStuff(Set<ID> recordIDs) {
    System.debug('recordIDs : + ' recordIDs);
    List<ContentVersion> content = [select ID from ContentVersion where ID in :recordIDs];
    System.debug('content : ' + content);
  }

}

 

A trigger that calls a future method, passes in the IDs of the record in the operation, and then retrieves those records from the database. Here's what happens:

 

The first debug statement shows that the recordIDs variable has a value

The second debug statement shows that the content is NOT retrieved - the list is empty.

 

Has anyone else seen this? Am I doing something wrong?

  • May 16, 2012
  • Like
  • 0

Has anyone else had issues with using apex:variable, apex:repeat, dynamic fields, and state not being preserved when actions take place?

 

I've got the following PoC, a page and its controller. The page shows the First Name and Last Name of a contact (hard coded ID - replace it with one of your own if you're trying this at home) as inputfields. The user can make changes and click a button and the changes should save. However, they do not.

 

First the page:

 

<apex:page tabStyle="Contact" controller="TestingPageCtrl">
    <div style="margin-top:14px">
        <apex:form >
                <apex:variable var="obj" value="{!sobj}"/>
                <apex:variable var="fieldNames" value="{!fields}"/>
                <apex:pageblock>
                    <apex:pageBlockSection>
                        <apex:repeat var="fieldName" value="{!fieldNames}">    
                            <apex:inputField value="{!obj[fieldName]}"/>
                        </apex:repeat>
                    </apex:pageBlockSection>
                </apex:pageBlock>

            <div style="width:610px">
                <apex:commandButton value="Next" style="float:right;" action="{!save}" />
            </div>
        </apex:form>
    </div>
</apex:page>

 

And now, the controller:

 

public class TestingPageCtrl {

    public SObject sobj {get; set;}
    public List<String> fields {get; set;}
    
    public TestingPageCtrl() {
        System.debug('In TestingPageCtrl');
        sobj = [select ID, FirstName, LastName from Contact where ID = '003K0000009T2za'][0];
        fields = new List<String> {'FirstName', 'LastName'};
    }

    public PageReference save() {
        System.debug('In save()');
        Database.update(sobj);
        return null;
    }
}

 

In the save() method, the changes made by the user are not carried across. There are some things I've noticed:

 

  • I actually first encountered this in a custom component. Using attributes (and passing the values in from the parent page) rather than variables works - however, there is some loss of elegance in the code.
  • You'll notice I'm using a repeat to loop over strings that are field names, and they are then used with dynamic bindings so that the controller can control what fields are displayed. Removing this repeat and putting hardcoded dynamic bindings (i.e. obj['FirstName']) works. Problem here is that my code becomes a lot less re-usable.
  • Looking at the debug logs, it looks as if the deserialization is not being performed when the action takes place.

 

I don't understand why this doesn't work as it is - is there something I'm missing or doing wrong? Do people think this should work as it currently it?

 

Any feedback and input would be greatly appreciated!

 

P.S. - I'm pretty sure this is not Summer '12 related as I was having this issue on Friday night before (and after) the upgrade.

  • May 14, 2012
  • Like
  • 0

Hi all,

 

I've posted before on Twitter about the browser-based developer console, and hinted at some of the issues I've had (overall though, I do like it), but not put them down in any meaningful fashion.

 

One of my dev orgs was updated to summer 12 this weekend and I've encountered an issue that's a real nusiance, so it's prompted me to post here to explain it in full. I'll also use this thread to list some of the other issues/areas for improvement.

 

Anyway, the main issue I'm having at the moment: before the update, the console was pretty good at working out when I had done something stupid and preventing the save, which allowed me to fix and save again once correct. After the update however, I get notified of the problem after I try to save, and worse, when I make changes, I can't save the file. I have to close the developer console window and open it again, re-do my changes and then save.

 

Previously I think this is how it worked:

  1. User made changes to code in the console
  2. As user made changes, either javascript on the page ran checks on the code, or sent the changes to the server - but did not commit them
  3. When the user clicked save, the file was committed. The user could only save if the console thought the code was valid i.e. if the code passed step 2.

 

Now, it's as if the following is happening:

  1. User makes changes to code in the console.
  2. User clicks save - it is only at this point that the code goes to the server.
  3. If there are errors in the code, the user is told there is an error. Internally, the console notes the code is invalid because the server has told it so.
  4. User fixes the error, but cannot save the code as the console believes the code is invalid, because the server told it. The console should try to save the file again and await the new result.

 

Hope that makes sense - any one else experiencing the same? I'm using Chrome, haven't tried other browsers as yet.

 

Other issues I've been meaning to post about:

 

  • No asterix on tab names - OK, this is a Summer 12 change. Previously, when you had multiple files open in the console, ones you'd changed but not saved were shown with an asterix against their name in the tab. This was useful but has been removed.
  • Refresh - Every now and again you'll get a message about having to refresh logs manually, even when there are no logs open. You get one of these messages for every class/page you have open.
  • Attribute suggestions - The editor can be a bit keen to suggest attributes for VF tags as you move around code. Actually this looks like it may have been fixed :)

 

Those are the only ones I spring to mind right now. I'll bookmark this thread and add more as I think of them.

 

I don't want to sound overly negative about the developer console - niggles aside, I was really quite happy with the last release's version, so much so that I made it my first choice for development over the Force.com IDE, and I really like the look of some of the things in the latest release. And it's all a long, long way away from the options we had, even as little as a year ago, so please keep up the great work :)

 

  • May 14, 2012
  • Like
  • 0

Hey all,

I'm a bit new to writting anything more than very simple Apex REST services. All the ones I have written have had one method per HTTP verb. There was one GET, one POST etc. So now I am writting something a bit more complex. This one needs to support 5 different GET methods, based on the request URL. Good REST design says have basic operations separated by slashes, and hide complexity behind the question mark. So I want to be able to do something like

 

//Methods for retreiving data from the system. All query methods accept
// fields parameter which specifies data returned in the query. All methods also accept
// a filter param which can accepts an SOQL where string to refine results.
//Methods include:

// /customer - get all customers
// /customer/Id - get customer based on dmp code, SSN, or Salesforce Record ID
// /customer/Id/cars - get all customer cars based on dmp code, SSN, or Salesforce Record ID
// /car - get all cars
// /car/vin - get car by VIN

//Ex: /customer?fields=name,firstname,email&filter=firstname='frank'
//get the name, firstname, and email for any contact with a firstname frank

//Ex: /car?filter=type__c='truck'
//Find all cars that are of type truck




So there are 5 different GET actions. Of course you can only declair one method as  @HttpGet annotated. So within that method you need to inspect the request URL and do different things. The only real way I know of to inspect the URL is through just basic string manipulation/inspection, which seems messy. I am just wondering if I am even on the right track, or if people have another method? My first thought is to take the URL, split it based on the / and evalutate the strings in the various positions to figure out what I need to do, but it seems like doing that is going to be very.. static also just begging for null pointer exceptions. Any thoughts on this would be great.

    @HttpGet
    global static list<sObject> doGet(RestRequest req, RestResponse res) 
    {
        list<sObject> returnValues = new list<sObject>();
        String queryObject = 'first element after first /';
        String queryObjectId = 'second element after first /, may be null';  
        string queryFields = 'id,name';
        
        if (req.params.containsKey('fields'))
        {
            queryFields = req.params.get('fields');
        }
        
        if(queryObject = 'customer')
        {
             //call the query customer method
        }
        else if(queryObject = 'car')
        {
         //call the query car method
        }
        
        
        
        
        return returnValues;
    }

 

 

USE CASE: I've queried a record from an object that contains a multiselect picklist field (Region__c):


Employee__c bsc = [SELECT id, Division__c, Region__c , User__c FROM Employee__c
WHERE User__c = :UserInfo.getUserId()];


Now, I want to pull all of the selected values of that Multiselect picklist field into a String[], so I can use that in another query.

The following query doens't work because bsc.Region__c is not a string -- but how can I query to see if Order__c.State__c is a member of bsc.Region__c?

oldestOrder = [SELECT id FROM Order__c
WHERE OwnerId = :q.QueueId AND
Status__c NOT IN :ignoreStatus AND
State__c IN :bsc.Region__c
ORDER BY First_Submit_Date__c

LIMIT 500][0].id;

What is the best way to query a three level parent child relationship? Assume you have the data model A > B > C.

 

You can't do this:

 

SELECT NAME, (SELECT Name, (SELECT Name FROM C__r) FROM B__r) FROM A

 

And you can't even do this:

 

(SELECT Name, (SELECT Name FROM C__r) FROM B__c)

 

But you can do this:

 

SELECT Name, (SELECT Name FROM B__r) FROM A__c

 

It would appear the only way to query the objects at the bottom of hte hierachy is when an entirely sepeare query. And then where do you put these? It would appear you need a seperate wrapper class to group everything together?

 

Thanks,

Jason

  • August 22, 2011
  • Like
  • 0

I am attempting to force creation of an opportunity on lead conversion of leads. I've attempted a trigger, but nothing I've tried so far seems to be working. This is what I've got so far:

 

trigger opptyCreationonConvert on Lead (before update) {     

List<Opportunity> o = new List<Opportunity>();
       for(Lead convertedLead: Trigger.new){

if(convertedLead.RecordTypeID == '012T00000000drN'&& convertedLead.IsConverted == TRUE && convertedLead.ConvertedOpportunityId == NULL){               

o.add (new Opportunity(

Name = convertedLead.Company,

CloseDate = date.today()+90,

StageName = '1 - Qualification'));

}

}

insert o;

}

How to turn on Delegated Authentication (SSO) for user ?

I have a requirement to configure SSO for 2 IDPs with different certificates. But  federated authetication allows configuration using only one certificate. So, can delegated authetication be used to configure SSO for two IDPs ?

  • April 26, 2011
  • Like
  • 0

Hi,

 

We want to use delegated authentication so that mobile users can access Salesforce mobile apps without entering usernames and passwords. We're looking to use username and passwords (rather than username & token).

 

When using delegated auth for desktops, you can (for example) provide a link on an intranet page for users that will take the user to a page that passes the user's username and password to salesforce.com in a POST request. That user has a delegated auth enabled profile, so salesforce.com passes the credentials to a delegated authentication authority.

 

That part I'm clear on!

 

What I want to know is - how does this work for mobile application users? If a user downloads Salesforce.com Mobile they need to identify to the application what their username and password is. But if a user is SSO enabled, this will mean nothing to them.

 

So how does a user identify who they are? Is this method reliant on users entering their email address as their username (and therefore it is implicit that their username will be the same as their email address) and their network password as their salesforce.com password? Or does the mobile need to be routed through a proxy that will pick up the attempt to visit the login page and construct the necessary POST request instead?

 

Any input appreciated, especially from anyone with experience of doing this!

 

  • March 25, 2011
  • Like
  • 0

I'm trying to create a map from a query list I created so I can access it by Id - here's the relevant code:

 

      List<User>userResults= new List<User>();
      set<Id>userIds = new Set<Id>();
      Map<Id,User>userData = new Map<Id,User>();

 

//code that fills user ids

 

    //get the relevant user data      
    userResults=[SELECT Id,MyField1__c,MyField2__c FROM User WHERE Id in: userIds];


    //put it into a map for easier access
    for (User u : userResults){
        userData.add(u.Id,u); //here's where the error is
    }

My List is of type User, the for loop u value is of type User and my map is Id, User so why doesn't it work?

I have a trigger on Task (after insert, after update) that I'm attempting to create test code for.  Below is a partial snapshot of the test class.  

 

...
Lead l1001b = new Lead(Company='Test1001b', LastName='Test1001b', OwnerID=UserId, NumberOfEmployees=1001);
Lead[] ld = new Lead[] {l1001b};
insert ld;

 

Where I'm having trouble is, I need to create a Task that is associated to the Lead record however, I receive the error "Field is not writeable: Who" with the syntax I have below. 

 

...
Task t1001b = new Task(Who=l1001b, Owner=UserId, Subject='Call', Status='Completed', Priority='Normal');
Task[] t = new Task[] {t1001b};
insert t;

 

I need to be able to create Tasks assocated to Leads and Contacts in order to adequately test my trigger.  Can anyone point me in the right direction?

 

Hi,


My main aim is to add some addition info to the data base after all the batchs are complete.. hence I need to invoke a database insert in the "final()" method of the Apex-batch job.


But I can see that the insert method is not called inside the finish() method. In fact i cannot even see the Syste.debug() messages added inside the finish() method.


Am sure that there is no exception been thrown inside the finish, as the status of the batch job is shown as completed (Also I have added an try catch block to doubl-check).


Please find below the sample code for your kind reference:


global class BatchAccountData implements Database.Batchable<SObject>{

// define a global variable:

List<My_CusObj__c> mylst = new List<MyCusObj__c>()

global Database.QueryLocator start(Database.BatchableContext bc) {
         Database.QueryLocator queryLocator = Database.getQueryLocator("select name,id from account");
         return queryLocator ;
   }

global void execute(Database.BatchableContext BC,
                              List<Account> accountListParam){

    for(Account acc: accountListParam ){
        MyCusObj__c obj = new MyCusObj__c();
      obj.Name = acc.Name+Bc.getJobId();
       mylst.add(obj);
    }
}

global void finish(Database.BatchableContext BC){
  insert mylst;    
}

}

Please provide me with your inputs, so that I can accomplish the aim.


Thanks in advance