Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi everyone,
I have ti generate a guid using formula field in salesforce.
Any idea.please let me know.
Thanks in advance
http://success.salesforce.com/ideaView?id=08730000000KgTYAA0
here's an apex class that will return a unique 16 digit ID:
global class GuidUtil { private static String kHexChars = '0123456789abcdef'; global static String NewGuid() { String returnValue = ''; Integer nextByte = 0; for (Integer i=0; i<16; i++) { if (i==4 || i==6 || i==8 || i==10) returnValue += '-'; nextByte = (Math.round(Math.random() * 255)-128) & 255; if (i==6) { nextByte = nextByte & 15; nextByte = nextByte | (4 << 4); } if (i==8) { nextByte = nextByte & 63; nextByte = nextByte | 128; } returnValue += getCharAtIndex(kHexChars, nextByte >> 4); returnValue += getCharAtIndex(kHexChars, nextByte & 15); } return returnValue; } global static String getCharAtIndex(String str, Integer index) { if (str == null) return null; if (str.length() <= 0) return str; if (index == str.length()) return null; return str.substring(index, index+1); }}
http://success.salesforce.com/ideaView?id=08730000000KgTYAA0
here's an apex class that will return a unique 16 digit ID:
global class GuidUtil {
private static String kHexChars = '0123456789abcdef';
global static String NewGuid() {
String returnValue = '';
Integer nextByte = 0;
for (Integer i=0; i<16; i++) {
if (i==4 || i==6 || i==8 || i==10)
returnValue += '-';
nextByte = (Math.round(Math.random() * 255)-128) & 255;
if (i==6) {
nextByte = nextByte & 15;
nextByte = nextByte | (4 << 4);
}
if (i==8) {
nextByte = nextByte & 63;
nextByte = nextByte | 128;
}
returnValue += getCharAtIndex(kHexChars, nextByte >> 4);
returnValue += getCharAtIndex(kHexChars, nextByte & 15);
}
return returnValue;
}
global static String getCharAtIndex(String str, Integer index) {
if (str == null) return null;
if (str.length() <= 0) return str;
if (index == str.length()) return null;
return str.substring(index, index+1);
}
}