You need to sign in to do that
Don't have an account?
Tyson Joe
Apex Controller Help: How to change Lead Owner
I've just started into Apex coding and could use some help. I borrowed a Class that someone posted online that allows a user to ACCEPT or REJECT a lead.
Where it changes the Status to 'Working - Accepted' - I want that to be the trigger that CHANGES OWNER to whoever clicked the action. Can someone help me with the script?
Where it changes the Status to 'Working - Accepted' - I want that to be the trigger that CHANGES OWNER to whoever clicked the action. Can someone help me with the script?
public class AcceptLead { public Lead l; /** * The constructor * * @param controller The standard controller */ public AcceptLead(ApexPages.StandardController controller) { this.l = (Lead) controller.getRecord(); } /** * The page action that will accept the lead * * @return The page to goto after loading */ public PageReference pageAction() { this.l.Status = 'Working - Accepted'; update this.l; return new PageReference('/' + this.l.Id); } }
<pre>
public class AcceptLead {
public Lead l;
/**
* The constructor
*
* @param controller The standard controller
*/
public AcceptLead(ApexPages.StandardController controller) {
this.l = (Lead) controller.getRecord();
}
/**
* The page action that will accept the lead
*
* @return The page to goto after loading
*/
public PageReference pageAction() {
this.l.Status = 'Working - Accepted';
this.l.OwnerId = UserInfo.getUserId(); // <== add this line
update this.l;
return new PageReference('/' + this.l.Id);
}
}
</pre>
All Answers
<pre>
public class AcceptLead {
public Lead l;
/**
* The constructor
*
* @param controller The standard controller
*/
public AcceptLead(ApexPages.StandardController controller) {
this.l = (Lead) controller.getRecord();
}
/**
* The page action that will accept the lead
*
* @return The page to goto after loading
*/
public PageReference pageAction() {
this.l.Status = 'Working - Accepted';
this.l.OwnerId = UserInfo.getUserId(); // <== add this line
update this.l;
return new PageReference('/' + this.l.Id);
}
}
</pre>