• peter paul 1
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,
I am trying to convert a trigger I wrote into an apex class and call the class from the trigger. I am receiving two errors when I copy the code into the class. I am hoping that someone on here can help me or give me a few pointers on what I can do to fix the problem. This is the trigger that fires correctly as a trigger.
trigger RunAssignmentRule on Lead (after update) {
    List<Lead> ls = new List<Lead>();

    for (Lead l : Trigger.new) {
    
    String oldVal = trigger.oldMap.get(l.id).Status;
    
        if (l.Status == 'Open/Requalified' && oldVal <> 'Open/Requalified') {
            ls.add(new Lead(id = l.id));
        }
    }
    
    if (ls.size() > 0) {
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;
    Database.update(ls, dmo);
}

}

The trigger makes a lead run back through the lead assignment when its status his open requalified. When I add it to an apen class I get two errors. An unexpected token error on the list and an error on for because it says it expected a } instead of the for. 

Thanks for your help,
Edward

 
component:
<aura:component implements="force:appHostable" controller="FetchRegistrations" >
    <aura:attribute name="reg" type="Registration__c[]"/>
    <ui:button label="Get Registrations" press="{!c.myAction}"/>
    <aura:iteration var="r" items="{!v.reg}" >
    <p>{!r.name}</p>
    </aura:iteration>
</aura:component>


Controller:
({
   myAction : function(component, event, helper) {
        var action = component.get("c.getAllregistrations");
        action.setCallback(this, function(response){
            var name = response.getState();
            if (name === "SUCCESS") {
                component.set("v.reg", response.getReturnValue());
            }
        });
     $A.enqueueAction(action);
    }
})

Apex:
global with sharing class FetchRegistrations {
@auraEnabled
    public static List<Registration__c> getAllregistrations()
    {
     List<Registration__c> reg=new LIST<Registration__c>();  
        reg=[select id,name,Email__c from Registration__c];
        return reg;
    } 
    public Registration__c getSelectedregistrations(Id id)
    {    
      Registration__c  reg=[select id,name,Email__c from Registration__c where id=:id];
        return reg;
    } 
   
}