Skip to content

Instantly share code, notes, and snippets.

View msrivastav13's full-sized avatar
🎯
Focusing

Mohith Shrivastava msrivastav13

🎯
Focusing
View GitHub Profile
List<Account> lstacc=[Select Id from Account limit 10000];
Set<Id> setIds=new Set<Id>();
for(Account a:lstacc){ //More CPU time for sure due to looping
setIds.add(a.id);
}
//Using Map query saves CPU time
//Fetching all account in map
Map<id,account> aMap = new Map<id,account>([Select Id,Name from Account limit 50000]);
// Generate an AES key for the purpose of this sample.
// Normally this key should be stored in a protected custom setting
// or an encrypted field on a custom object
Blob cryptoKey = Crypto.generateAesKey(256);
// Generate the data to be encrypted.
Blob data = Blob.valueOf('Test data to encrypted');
// Encrypt the data and have Salesforce.com generate the initialization vector
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
// Decrypt the data - the first 16 bytes contain the initialization vector
string xldata='<data>xml sample data</data>';
blob b=blob.valueOf(xldata);
Blob encryptedData = Crypto.encryptWithManagedIV('AES256',blob.valueOf('00000000000000000000000000000000'), b);
String blobstr=encryptedData.toString();
system.debug('&&&&'+encryptedData);
string xldata='<data>xml sample data</data>';
blob b=blob.valueOf(xldata);
Blob encryptedData = Crypto.encryptWithManagedIV('AES256',blob.valueOf('00000000000000000000000000000000'), b);
//String blobstr=encryptedData.toString();//Not Effective and generates ERROR BLOB is not Valid UTF-8 String
String b64=EncodingUtil.base64Encode(encryptedData);
system.debug('&&&&'+b64);
//Code for Encryption
string xldata='<data>xml sample data</data>';
blob b=blob.valueOf(xldata);
Blob encryptedData = Crypto.encryptWithManagedIV('AES256',blob.valueOf('00000000000000000000000000000000'), b);
//String blobstr=encryptedData.toString();//Not Effective and generates ERROR BLOB is not Valid UTF-8 String
String b64=EncodingUtil.base64Encode(encryptedData);
system.debug('&&&&'+b64);//Store this in a Custom Long Text Field as this is a String
//Code for Decryption
Blob b64decoded=EncodingUtil.base64Decode(b64);
<s:Envelope xmlns:s="Schema URL">
<s:Body>
<GetActivationInformationResponse xmlns="Schema URL">
<GetActivationInformationResult xmlns:a="Schema URL" xmlns:i="Schema URL">
<a:ATMFee>*****</a:ATMFee>
<a:ActivationData>******</a:ActivationData>
<a:ActivationType>PIN</a:ActivationType>
<a:LastVerificationResponse>
<a:ActivitiesPerformed i:nil="true"/>
<a:CardLimitAccountList i:nil="true"/>
Dom.Document doc = new Dom.Document();
doc.load(xmlstringdata);//Here xmlstring data is from the above XML shown above
//Retrieve the root element for this document.
Dom.XMLNode env= doc.getRootElement();
//system.debug('****'+env);
dom.XmlNode Body=env.getChildElement('Body','Schema URL');
//system.debug('&&&&'+Body);
Dom.XMLNode GetActivationInformationResponse=Body.getChildElement('GetActivationInformationResponse','Schema URL');
//system.debug('NEW'+GetActivationInformationResponse);
Dom.XMLNode GetActivationInformationResult=GetActivationInformationResponse.getChildElement('GetActivationInformationResult','Schema URL');
$(function() {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MobileHomeCtrl.fetchallUsers}',
function(result, event){
if (event.status) {
var availableTags = [];
$.each(result,function(){
var obj = new Object();
//match the passed label and returned value to populate the label and value
obj.label = this['FirstName']+' '+this['LastName'];
public class CommunityHelper{
public static String communityId=Network.getNetworkId();
public static ConnectApi.Community getCommunityInfo(){
if(communityId!=null){
return connectapi.Communities.getCommunity(communityId);
}else {
return null;
}
public class ParentChildMapHelper{
public static Map<String,List<sobject>> buildGeneralisedMap(String fieldname,List<Sobject> lstsobject){
Map<String,List<sobject>> mapIdbySobject=new Map<String,List<sobject>>();
for(Sobject s:lstsobject){
if (mapIdbySobject.containsKey((String)s.get(fieldname))){
mapIdbySobject.get((String)s.get(fieldname)).add(s); //tricky part .Here map.get(key) is returning list and we are adding contacts to the list
} else{
List <sobject> lstsobjects = new List <sobject> (); //Initialize list as no key is found before and first time we get key
lstsobjects.add(s);
mapIdbySobject.put((String)s.get(fieldname), lstsobjects);