cancel
Showing results for 
Search instead for 
Did you mean: 

5 primary keys

former_member200567
Active Contributor
0 Kudos

Hi,

I want to make 5 primary keys in my BO. I used AlternativeKey option but it has the limitation of must-have different data types. And they are not working as same as Primary Keys in Database.

So, please help.

Any help is appreciated.

Regards.

May T.

Accepted Solutions (1)

Accepted Solutions (1)

former_member200567
Active Contributor
0 Kudos

Hi,

Is there any code or logic that can solve the compound problems.?

Thanks, everyone.

Best Regards,

May T.

sunil1101
Advisor
Advisor
0 Kudos

Hi May T,

You can define one element as alternative key and other 5 five elements as non-alternative elements in your BO

[AlternativeKey]element myKey:ID;

element keyA:ID;

element KeyC:ID;

element KeyB:ID;

element KeyD:ID;

element KeyE:ID;

Then in BeforeSave you can concatenate all 5 non-alternative fields and assign it into alternative field

import ABSL;

if(this.KeyA.IsInitial() && this.KeyB.IsInitial()&& this.KeyC.IsInitial() && this.KeyD.IsInitial() && this.KeyE.IsInitial())

{

var a = this.KeyA.Concatenate(this.KeyB).Concatenate(this.KeyC).....so on

this.myKey = a;

}

You can always identify your instance using alternative key, but using other ID there would be chance you will receive more than one instance.

Hope this help

Sunil

former_member200567
Active Contributor
0 Kudos

Thanks Sunil,

I will try with this.

Regards.

May T.

former_member200567
Active Contributor
0 Kudos

Hi, Sunil Maurya.

That's very wise of you, Sunil.

Your code works.

Thanks,

Regards.

May T

former_member200567
Active Contributor
0 Kudos

Hi, Sunil Maruya.

There is one strange thing. BeforeSave is executed just one time after "instance with same key error" comes out. Whatever I change my data, it shows the same error.  So I have to write it in EventAfterModify. It works in AfterModify perfectly.

Thanks Sunil,

May T

vinodkumar_kommineni
Active Contributor
0 Kudos

Hi May T,

If the standard Code throws an error then the Custom code after it is just ignored by the system. This is the reason for the behavior you observed.

Regards

Vinod

Answers (3)

Answers (3)

former_member200567
Active Contributor
0 Kudos

Hi,

I am not an expert either. So still not sure about the Alternative Key. But as Fernando Giroleti said,

2 or more Alternative Keys are not working like a compound PK. So I use some coding in BeforeSave not to save the same data again.It kind of works . But the problem is in Edit. The logic becomes silly in Edit.

Thanks for discussion,

Regards

May T

vinodkumar_kommineni
Active Contributor
0 Kudos

Hi May,

Yes, It does not work as a compound Key in Cloud. Its a kind of silly but that is how it is designed

Regards

Vinod

Former Member
0 Kudos

Hi,

I might be wrong, but an Alternative Key is not a Primary Key (as per its name...). The PK is not exposed for us. If you set 2 or more Alternative Keys, it won't work like a Compound PK.

As I said, I am not 100% sure about what I am saying, and would be great to have some more experts here to talk about.

That's a good discussion,

Best regards,

Fernando

vinodkumar_kommineni
Active Contributor
0 Kudos

Hi May,

Unfortunately, that is the limitation in cloud. You cannot have Alternative Keys of same Data Type and you cannot expect them to behave like a normal primary key in on premise DB.

Here you should make a filed alternative key if that particular column is unique not the set of columns.

More over we had serious issues where our custom object had 3 Alternative Keys and Retrive does not work properly on all the fields. When we search on second field it used to try to fetch the record based on first field. When we raised it to SAP they had told it is picking Alphabetically first one and they are working on it to fix the problem. But as of now it is not yet fixed.

So my suggestion would be use Alternative Key on multiple fields if it is really required, if possible redesign your BO.

Regards

Vinod