-4

Can Someone help me with this trigger : It is not working

trigger ControlOpportunityStage on Line_Item__c (after update) {
    List<Opportunity> parentlist = new List<Opportunity>();
    List<Opportunity> opportunityId = new list<Opportunity>();

    for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName 
                             from Line_item__c
                             where Line_item__c.Opportunity__c <> null]){

        for(Opportunity opt : parentlist)
            if(Opportunity.StageName != Line_item__c.Stage__c)
                Opportunity.StageName = "Line_item__c.Stage__c;
                opportunityId.add(opportunity.Id);
        {
             if(opportunityId != null & opportunityId.Size()>0)
             update opportunityId;
        }     
    }
}

2 Answers 2

10

You've declared:

List parentlist = new List();
List opportunityId = new list();

It should be:

List<Opportunity> parentlist = new List<Opportunity>();
List<ID> opportunityId = new List<ID>();

You have this block of code (I just formatted the section, did not alter anything):

for(Line_item__c lirecord : [SELECT Opportunity__r.id, Opportunity__r.StageName FROM Line_item__c WHERE Line_item__c.Opportunity__c <> null]) {
  for(Opportunity opt : parentlist)
    if(Opportunity.StageName != Line_item__c.Stage__c)
      Opportunity.StageName = "Line_item__c.Stage__c;
      opportunityId.add(opportunity.Id);

You need to use enclosing brackets and quotes. You have:

for(Opportunity opt : parentlist)

It should be:

for (Opportunity opt : parentlist) {

You have a random " in:

Opportunity.StageName = "Line_item__c.Stage__c;

Honestly, it seems like you made no effort to follow syntax at all and just hoped someone would make it compilable for you....I guess I've been tricked.

3
  • 5
    Yup, you spent more time on your answer than the OP did in writing the code and posting the question....
    – Eric
    Commented Jul 16, 2015 at 20:48
  • 4
    There are, I suppose, up to 18 errors, depending on your view point on errors (I'm pretty strict, so...).
    – sfdcfox
    Commented Jul 16, 2015 at 21:36
  • 2
    A for effort, but I agree with Eric. You did the OP a favor. :) Commented Jul 16, 2015 at 23:36
0

You have not needed double quotes sign.
Opportunity.StageName = Line_item__c.Stage__c;

3
  • I am a new Salesforce Admin, I have no experience with Apex, and I am very new to the language, I was directed to this site for assistance and I appreciate the help.
    – Ram Sidhu
    Commented Jul 17, 2015 at 21:55
  • Furthermore the corrections do not make it work...I still get an error after using the trigger below: Expression cannot be assigned at line -1 column -1
    – Ram Sidhu
    Commented Jul 17, 2015 at 22:00
  • @RamSidhu, I suggest you start with "Hello World". It will be the best solution. Commented Jul 18, 2015 at 16:46

Not the answer you're looking for? Browse other questions tagged .