illegal assignment from object to id Error?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I have written following code to insert records on junction object.
public static List<PDCN__c> addSelectedPDCNs(List<String> selectedRecords, String groupId)
system.debug('Entering addSelectedPDCNs');
system.debug('Selected Records are-->'+selectedRecords);
system.debug('Group Id is-->'+groupId);
List < PDCN__c > lstAddId = [SELECT Id from PDCN__c where Name IN: selectedRecords];
system.debug('Record Ids Are-->'+lstAddId);
List<PDCNGrpJunc__c> lstJunc = new List<PDCNGrpJunc__c>();
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
juncRec.PDCN__c = pdcn;
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
//insert lstJunc;
try
system.debug('Trying Insert');
system.debug('');
insert lstJunc;
catch(Exception e)
System.debug('Exception Occured='+e.getMessage());
return lstAddId;
I am getting error in juncRec.PDCN__c = pdcn; line as :-
Illegal assignment from PDCN__c to Id
Why do I get this error? How do I fix it?
apex compile-error
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I have written following code to insert records on junction object.
public static List<PDCN__c> addSelectedPDCNs(List<String> selectedRecords, String groupId)
system.debug('Entering addSelectedPDCNs');
system.debug('Selected Records are-->'+selectedRecords);
system.debug('Group Id is-->'+groupId);
List < PDCN__c > lstAddId = [SELECT Id from PDCN__c where Name IN: selectedRecords];
system.debug('Record Ids Are-->'+lstAddId);
List<PDCNGrpJunc__c> lstJunc = new List<PDCNGrpJunc__c>();
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
juncRec.PDCN__c = pdcn;
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
//insert lstJunc;
try
system.debug('Trying Insert');
system.debug('');
insert lstJunc;
catch(Exception e)
System.debug('Exception Occured='+e.getMessage());
return lstAddId;
I am getting error in juncRec.PDCN__c = pdcn; line as :-
Illegal assignment from PDCN__c to Id
Why do I get this error? How do I fix it?
apex compile-error
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have written following code to insert records on junction object.
public static List<PDCN__c> addSelectedPDCNs(List<String> selectedRecords, String groupId)
system.debug('Entering addSelectedPDCNs');
system.debug('Selected Records are-->'+selectedRecords);
system.debug('Group Id is-->'+groupId);
List < PDCN__c > lstAddId = [SELECT Id from PDCN__c where Name IN: selectedRecords];
system.debug('Record Ids Are-->'+lstAddId);
List<PDCNGrpJunc__c> lstJunc = new List<PDCNGrpJunc__c>();
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
juncRec.PDCN__c = pdcn;
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
//insert lstJunc;
try
system.debug('Trying Insert');
system.debug('');
insert lstJunc;
catch(Exception e)
System.debug('Exception Occured='+e.getMessage());
return lstAddId;
I am getting error in juncRec.PDCN__c = pdcn; line as :-
Illegal assignment from PDCN__c to Id
Why do I get this error? How do I fix it?
apex compile-error
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have written following code to insert records on junction object.
public static List<PDCN__c> addSelectedPDCNs(List<String> selectedRecords, String groupId)
system.debug('Entering addSelectedPDCNs');
system.debug('Selected Records are-->'+selectedRecords);
system.debug('Group Id is-->'+groupId);
List < PDCN__c > lstAddId = [SELECT Id from PDCN__c where Name IN: selectedRecords];
system.debug('Record Ids Are-->'+lstAddId);
List<PDCNGrpJunc__c> lstJunc = new List<PDCNGrpJunc__c>();
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
juncRec.PDCN__c = pdcn;
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
//insert lstJunc;
try
system.debug('Trying Insert');
system.debug('');
insert lstJunc;
catch(Exception e)
System.debug('Exception Occured='+e.getMessage());
return lstAddId;
I am getting error in juncRec.PDCN__c = pdcn; line as :-
Illegal assignment from PDCN__c to Id
Why do I get this error? How do I fix it?
apex compile-error
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Sep 7 at 14:24


Adrian Larson♦
100k19106224
100k19106224
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Sep 7 at 11:56
Rohit Mishra
111
111
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Rohit Mishra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
So the field juncRec.PDCN__c
is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn
is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are trying to do is assign an Object to a Text/Id field and hence you get an error. You can solve this by using id juncRec.PDCN__c = pdcn.Id;
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
***juncRec.PDCN__c = pdcn.Id;***
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
So the field juncRec.PDCN__c
is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn
is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are trying to do is assign an Object to a Text/Id field and hence you get an error. You can solve this by using id juncRec.PDCN__c = pdcn.Id;
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
***juncRec.PDCN__c = pdcn.Id;***
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
add a comment |Â
up vote
5
down vote
So the field juncRec.PDCN__c
is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn
is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are trying to do is assign an Object to a Text/Id field and hence you get an error. You can solve this by using id juncRec.PDCN__c = pdcn.Id;
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
***juncRec.PDCN__c = pdcn.Id;***
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
add a comment |Â
up vote
5
down vote
up vote
5
down vote
So the field juncRec.PDCN__c
is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn
is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are trying to do is assign an Object to a Text/Id field and hence you get an error. You can solve this by using id juncRec.PDCN__c = pdcn.Id;
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
***juncRec.PDCN__c = pdcn.Id;***
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
So the field juncRec.PDCN__c
is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn
is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are trying to do is assign an Object to a Text/Id field and hence you get an error. You can solve this by using id juncRec.PDCN__c = pdcn.Id;
for( PDCN__c pdcn : lstAddId )
system.debug('Inside For Loop-->'+pdcn);
PDCNGrpJunc__c juncRec = new PDCNGrpJunc__c();
***juncRec.PDCN__c = pdcn.Id;***
juncRec.PDCN_Group__c = groupId;
lstJunc.add(juncRec);
answered Sep 7 at 12:04


Pranay Jaiswal
8,73431848
8,73431848
add a comment |Â
add a comment |Â
Rohit Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Rohit Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Rohit Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Rohit Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231606%2fillegal-assignment-from-object-to-id-error%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password