function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raysfdc1988raysfdc1988 

Error: Compile Error: Invalid bind expression type of Schema.SObjectField for column of type String at line 143

if(trigger.isupdate){
list<Referral_Points__c> referral=new list<Referral_Points__c>();
list<Student_Profile__c> studentlist= new list<Student_Profile__c >();
for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.Refered_Person__c= [select id from Student_Profile__c where Student_Profile__c.UserName__c=:Student_Profile__c.Referred_By_email__c];//////line 143
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}

Please help
Subhash GarhwalSubhash Garhwal
Hi Ray,

In your case you want Refered_Person__c = Student_Profile__c if Student_Profile__c's UserName__c = Referred_By_email__c

if(s.UserName__c == s.Referred_By_email__c)
rp.Refered_Person__c= s.Id

Or if you want to bind any other field than

if(s.UserName__c == s.Referred_By_email__c)
rp.Refered_Person__c= s.FieldAPIName

Thanks

raysfdc1988raysfdc1988
for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.Refered_Person__c= [select id from Student_Profile__c where Student_Profile__c.UserName__c=:Student_Profile__c.Referred_By_email__c];//////line 143
referral.add(rp);

Here i am checking with if(s.Course_Program__c !=null)....
once its not null den i need to creat record of object Referral_Points__c,
rp.Refered_Person__c is lookup field to Student_Profile__c


Is there any error in query..pl help..thanks
Subhash GarhwalSubhash Garhwal
Than you don't need to apply soql query,Just simply assign Student_Profile__c's Id in Refered_Person__c field

Like :  


for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null) {

Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.Refered_Person__c= s.Id;
referral.add(rp);
Vinit_KumarVinit_Kumar
I totally don't understand as what you are trying to do here and your SOQL syntax is also not correct.

Is your trigger running on after insert event or before insert event coz in before event you will not get the Id or it is running or only update events.


raysfdc1988raysfdc1988
thanks vinith, I got it ..its after event.

if(trigger.isupdate){

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.points__c=50;
Student_Profile__c referedpersonid=[select id from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];
rp.Refered_Person__c =referedpersonid.id;
referral.add(rp);
}
}
This is solution...