You need to sign in to do that
Don't have an account?

Cross Object Field Update - Apex Trigger
Hi Everybody,
I'm pretty new to Apex and have been trying to do a cross object field update. I have two objects Lead and Candidate_Non_Member_c and I want to have the field Candidate_Non_Member__c.Called_C equal to 1 when the Lead.Disposition = ' Registered'. Also the only way to find the corresponding candidate to the lead is by phone number. Lead.Phone and Candidate_Non_Member__c.Formated_Phone_Number__c.
This is what I have so far but I've been getting "Error: Compile Error: Expression cannot be assigned at line -1 column -1"
Any help would be great.
Thanks!
trigger Lead_To_Candidate_2 on Lead (after insert, after update)
{
String objemail;
String objfirstname;
String objphone;
for(Lead obj: Trigger.new)
{
if (Lead.disposition__c = 'Registered')
{
objemail = obj.Email;
objfirstname = obj.Name;
objphone = obj.Phone;
}
}
List<Candidate_Non_Member__c> candidate = new List<Candidate_Non_Member__c>([SELECT Id, Formated_Phone_Number__c, Called__c FROM Candidate_Non_Member__c WHERE Formated_Phone_Number__c = :objphone]);
List<Candidate_Non_Member__c> candidateUpdateList = new List<Candidate_Non_Member__c>();
for(Candidate_Non_Member__c c: candidate)
{
Candidate_Non_Member__c.Called__c = 1;
}
if(candidateUpdateList.size() > 0)
{
update candidateUpdateList;
}
}
Please try this:
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
All Answers
if (Lead.disposition__c = 'Registered')
It probably should be
if (obj.disposition__c = 'Registered')
you have the same type of error towards the bottom
Candidate_Non_Member__c.Called__c = 1;
should be
c.Called__c = 1;
Also, you never add anything to candidateUpdateList so it's always empty. I think you want:
c.Called__c = 1;
candidateUpdateList.add(c);
in that spot.
Please try this:
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods