Are SFDC IDs unique across all of SFDC or can you only assume an ID is unique within a particular org? If an sObject with a particular ID is deleted, could that ID come back again in the same org or another one for a new sObject?
[SalesForce] Salesforce ID Uniqueness
Related Solutions
I'm not sure that the case insensitive Ids work like that. With your all lowercase ID I'm guessing Salesforce is looking for an OpportunityShare (keyPrefix 00t) rather than a Task (00T). Odd that they aren't using the suffix information.
The suffix is enough to make the ID appear to be insensitive in something like Excel, but it doesn't mean you can convert it all to lowercase in Salesforce.
Try 00TU000000Nf5NPMAZ on the URL.
Writing something to revert the casing just seemed like too much fun to be left undone.
This is in C#, but I've tried to avoid things like LINQ and framework classes (BitArray) to make it more language agnostic. It does bloat it a bit, but hopefully you get the idea. There are several areas that would benefit from some additional error checking.
private static char[] characterMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".ToCharArray();
private static bool[] BitPatternForChar(char c)
{
c = Char.ToUpper(c);
byte characterMapIndex = byte.MinValue;
for(byte i = 0; i<characterMap.Length; i++)
{
if(characterMap[i] == c)
{
characterMapIndex = i;
break;
}
}
// Get the Bit Pattern for the byte
bool[] result = new bool[5];
for (int bitNumber = 0; bitNumber < result.Length; bitNumber++)
{
result[bitNumber] = (characterMapIndex & (1 << bitNumber)) != 0;
}
return result;
}
public static string RepairCasing(string lowercaseInsenstiveId)
{
if (string.IsNullOrEmpty(lowercaseInsenstiveId))
{
throw new ArgumentNullException("lowercaseInsenstiveId");
}
else if (lowercaseInsenstiveId.Length != 18)
{
throw new ArgumentException("lowercaseInsenstiveId should be 18 characters", "lowercaseInsenstiveId");
}
List<bool> toUpperBits = new List<bool>(15);
bool[] isUpperCaseChar = BitPatternForChar(lowercaseInsenstiveId[15]);
toUpperBits.AddRange(isUpperCaseChar);
bool[] isUpperCaseChar2 = BitPatternForChar(lowercaseInsenstiveId[16]);
toUpperBits.AddRange(isUpperCaseChar2);
bool[] isUpperCaseChar3 = BitPatternForChar(lowercaseInsenstiveId[17]);
toUpperBits.AddRange(isUpperCaseChar3);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 15; i++)
{
Char c = lowercaseInsenstiveId[i];
if (toUpperBits[i])
{
c = Char.ToUpper(c);
}
else
{
c = Char.ToLower(c);
}
sb.Append(c);
}
sb.Append(lowercaseInsenstiveId.Substring(15, 3).ToUpper());
return sb.ToString();
}
You can clone the entire attachment and then delete the old one.
this code works for me :
List<Attachment> attachmentsToInsert = new List<Attachment>();
List<Attachment> attachmentsToDelete = new List<Attachment>();
Attachment tempAtt;
for(Attachment attachment: [
SELECT SystemModstamp, ParentId, OwnerId, Name,
LastModifiedDate, LastModifiedById, IsPrivate, IsDeleted,
Id, Description, CreatedDate, CreatedById,
ContentType, BodyLength, Body
FROM Attachment
WHERE parentId=:'parentid']) {
tempAtt=attachment.clone(false,false);
tempAtt.parentId = quoteSelWrap1.quot.Id;
attachmentstoInsert.add(tempAtt);
attachmentsToDelete.add(attachment);
}
insert attachmentsToInsert;
delete attachmentsToDelete;
Best Answer
For your initial question:
Reference
http://boards.developerforce.com/t5/General-Development/are-user-ids-unique-across-all-salesforce-com-prod-orgs/td-p/234975
Short Answer
Yes for Production Orgs (Sandbox's can have the same object Id as the Production Org they were cloned from)
For your second question:
I would expect this to be the case however I wouldn't rely on it as with any auto increment field in a database there could come a day when those Id's are reallocated for use.