• davidwat
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies

Hi all,

I have recently faced a problem while creating an apex class for inserting two records from a visulaforce page. I want to insert the contact info in contact object and then want to get the Id of that contact  record to assign it to ContactId in the Campaignmember object. But got error that the Id is null. Here is my code goes

 

Creating contact object:

----------------------------------------

Contact cont= new conatct();

cont.LastName=lastname;

...

...

insert cont;

That  works fine and the contact is being inserted

--------------------------------------------

Now  when I want to get the Id of the above record it given me an error

CampaignMember CaMem = new CampaignMember();

CaMem.ContactId  =cont.Id;

 

insert  CaMem;   // Error: the conatctId is null.

 

It means that the cont.Id is null. One way is to query the contact records and order them by a fields like creadteddate etc and get the last or first record and suppose that it is the one inserted just recently. I am not going with this solution.

 

Does anyone know how to solve this issue? Is there some system method that keep the id with its insertion inline to use it down in the code?

 

Any usefull suggestions please. Thanks for your support and help

 

 

 

 

i have a key as a byte array like this

 

byte[] key={1,45,12,74,52,....upto 32 bytes values}

 

can someone tell me how to use the above array in encrypt (algo_name,key,IV,data) function?

 

The function parameter key require a 32 byte blob value. I have no idea how to convert the above key array to the valid blob format of 32 bytes.



Can someone tell me how to represent a byte array in apex?

Say i have a byte array 

byte[] vk = {1,24,45,26,75};

is there is some way to write this array in salesforce? 

please replay, the answer that solve this will be selected as a best answer. thanks

 

Hi,

i am facing problem to use encrypt function to encrypt my data using my own key and
initialization vector. I need to encrypt data for the posting it to my .net site. I will
decrypt the encrypted string in .Net.
Thus i have generated the key and initialization vector in .net like that, and i need to encrypt the data using this otherwise i can not decrypt it in my .net site.
byte[] key  = { 20, 5, 3, 58, 170, 151, 146, 82, 10, 45, 72, 93, 179, 6, 151, 63, 91, 19, 5 ...upto 32};
byte[] IV     = {15, 36, 12, 1, 77, 29, 27, 60,73, 13, 4, 2, 6, 1, 21, 61 };

No the problem is this i need to encrypt my data in apex using this and byte is not a valid data type in apex, also i need to represent the key and IV using blob. 

I have converted my key array to a string array by converting each byte to its hexa decimal equivalent but it not work for me as the string was increased to 64 charactor. Also i am not sure that by this conversion i will lost the actual key or not?

I have no idea what to do with this, my code is like that

 //byte[] key  = { 20, 5, 3, 58, 170, 151, 146, 82, 10, 45, 72, 93, 179, 6, 151, 63, 91, 19, 5 ...upto 32};
 // byte[] IV     = {15, 36, 12, 1, 77, 29, 27, 60,73, 13, 4, 2, 6, 1, 21, 61 };
string key_test ='a5b08661bcbba014f2dc3d38aafa3417';  //9e463392526e2d485db306971f5bdb05';
string key_IV    ='0588660eb1e5f71d';                     //497b19a2a06fd644';
blob key_b = blob.valueof(key_test);
blob IV_b = blob.valueof(key_IV);
blob data = blob.valueof(inputString)
Blob encryptedData = Crypto.encrypt('AES256',key_b ,IV_bdata);
string  encrypted_str = EncodingUtil.base64Encode(encryptedData);
if someone tell me how to encrypt the data for the external site in apex using the key and IV when provided by other as above.
i know its challenging but salesforce is the field of challenging people, please help me through this issue, every response to this question will be appreciated. Thanks



Can someone tell me how to represent a byte array in apex?

Say i have a byte array 

byte[] vk = {1,24,45,26,75};

is there is some way to write this array in salesforce? 

please replay, the answer that solve this will be selected as a best answer. thanks