I'm not certain if once I've created a URL via a string, it needs to be treated as a WebLink in order to save it in a list, but every time I try to save a list of them as strings, I get an empty list. Could someone please tell me what's happening and how to work around it?

Here's the situation. I'm creating links between related objects (Events and Assignments__c) and need to be able to query between the two for confirmation. The links of course contain the ID's of the related object which I have to sync using the related URL's/Id's.

Here's an example of some code that won't work for me:

    string Relurls; // Related Event Link URL

    for(Event evt:Assnmnt){

        Relurls = (URL.getSalesforceBaseUrl().toExternalForm() + '/' + evt.Id);

        System.debug('Related Event Link URL: ' + Relurls); 

        // these are always valid strings


        Assignments__c ass = new Assignments__c(Description__c = evt.Description, StartDateTime__c = evt.StartDateTime, EndDateTime__c = evt.EndDateTime, ActivityDate__c = evt.ActivityDate, DurationInMinutes__c = evt.DurationInMinutes, Subject__c = evt.Subject, OwnerID = evt.WhoID, Related_Activity_Event__c = Relurls ); 


    if(nwAssnmnt.IsEmpty() == false){

        Database.SaveResult[] srList = Database.insert(nwAssnmnt, false);

        /* confirm Assignments__c records insertion */

        for(Database.SaveResult srna: srList){


    } //end if(nwAssnmnt.IsEmpty()

    /* confirm Assignments__c records insertion */

    system.assertEquals(RAELS.size(), srListIds.size()); // <--- this fails

    list<Assignments__c> AssnCnfrm = [select Id, Description__c, StartDateTime__c, Related_Activity_Event__c from Assignments__c where Related_Activity_Event__c =: RAELS] ;

    // above query fails if I use the list of URLs (the list RAELS is empty)  
    // but not if I use the clause where Id = srListIds                

So what's going on? Any ideas? I'm not certain either how, or that it would work, to query on the related objects using a clause that states the Id string is contained in the Related_Activity_Event__c URL string.


I tried using the Related_Activity_Event__c IN :RAELS and it didn't work. It appears that I'm getting data added to the list. Here's confirmation from the debug log of some of what's happening:

12:31:14.512 (512319000)|USER_DEBUG|[82]|DEBUG|Related Event Link URL: httpx://XXXX.salesforce.com/00Ue0000001dmnMEAQ

12:31:14.512 (512351000)|SYSTEM_METHOD_ENTRY|[85]|LIST.add(Object) <<- LIST RAELS

12:31:14.512 (512896000)|DML_BEGIN|[96]|Op:Insert|Type:Assignments__c|Rows:1

12:31:14.529 (529330000)|DML_END|[96]

12:31:14.530 (530387000)|SOQL_EXECUTE_BEGIN|[114]|Aggregations:0|select Id, Description_c, StartDateTime_c, Related_Activity_Event_c from Assignments_c where Assignments__c.Related_Activity_Event__c IN :tmpVar1 <<--- (RAELS)

12:31:14.535 (535060000)|SOQL_EXECUTE_END|[114]|Rows:0

Any other thoughts?

  • You can debug the errors of your saveResults.
    – Adrian Larson
    Commented Aug 2, 2013 at 21:43
  • After you check .isSuccess, add an else block and debug .getErrors(). Check out the documentation.
    – Adrian Larson
    Commented Aug 2, 2013 at 21:44
  • Thanks for the suggestion. I was probably doing that when you posted along with adding a number of other system.debug statements. :) Problem solved. It showed up in the .getErrors(). Was a field error with the Owner ID's being passed that was the culprit. They were actually contact ID's and the "false" setting was allowing all the records to insert with bad OwnerIds. Their passing unnoticed was apparently creating all the other problems.(sigh)
    – crmprogdev
    Commented Aug 3, 2013 at 2:16

2 Answers 2


This issue makes sense to me:

system.assertEquals(RAELS.size(), srListIds.size()); // <--- this fails

since you're calling Database.insert(nwAssnmnt, false); which means it won't fail the entire insert if just one of the inserts fails (false = partial processing is permitted). So just one fail would mean your two lists would be of different sizes.

As for your SOQL statement, I believe you want to do an IN. So:

Related_Activity_Event__c IN :RAELS

would check for Related_Activity_Event__c in all of the elements in RAELS.

  • The system assert is primarily there right now for development while I sort this out. In a test class, there shouldn't be any partial processing. I do understand your point and it is a valid one. I was getting null pointer errors earlier that seemed related to the list. Will try the change in the query and see if that fixes things. Thnx!
    – crmprogdev
    Commented Aug 2, 2013 at 18:13

Adam's post led me to the true cause of the problem which also merits posting a separate answer.

Database.insert(nwAssnmnt, false); was allowing errors in the OwnerID Field to occur while still inserting the records. In my investigations, I discovered that the OwnerIDs I was trying to pass were actually contact ID's. Inserting the records with invalid OwnerID records was apparently creating all the other problems I was experiencing.(sigh)

I'd have expected this to have been a fatal error since it's an important required field, but apparently that wasn't the case; so it's something I'll be watching for in the future!

I forgot to add, once the above problem was fixed, Related_Activity_Event__c IN :RAELS also fixed the query problem. :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .