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
RAELS.add(Relurls);
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 );
nwAssnmnt.add(ass);
}
if(nwAssnmnt.IsEmpty() == false){
Database.SaveResult[] srList = Database.insert(nwAssnmnt, false);
/* confirm Assignments__c records insertion */
for(Database.SaveResult srna: srList){
if(srna.IsSuccess()){
srListIds.add(srna.getID());
}
}
} //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.
Update
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?
.isSuccess
, add an else block and debug.getErrors()
. Check out the documentation.