-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;
        }     
    }
}

closed as off-topic by Eric, Mark Pond, Vamsi Krishna, Boris Bachovski, Chris Duncombe Jul 16 '15 at 23:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Eric, Mark Pond, Vamsi Krishna, Boris Bachovski, Chris Duncombe
If this question can be reworded to fit the rules in the help center, please edit the question.

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.

  • 5
    Yup, you spent more time on your answer than the OP did in writing the code and posting the question.... – Eric Jul 16 '15 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 Jul 16 '15 at 21:36
  • 2
    A for effort, but I agree with Eric. You did the OP a favor. :) – Chris Duncombe Jul 16 '15 at 23:36
0

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

  • 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 Jul 17 '15 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 Jul 17 '15 at 22:00
  • @RamSidhu, I suggest you start with "Hello World". It will be the best solution. – Andrii Muzychuk Jul 18 '15 at 16:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.