You need to sign in to do that
Don't have an account?
ali-kantar1.3897183320927883E12
can someone help me identify what is going wrong in the apex Method
i have written this method but it keeps giving me this error :
Error: Compile Error: Variable does not exist: childOpps at line 14 column 23
public class StandardControllerExtension {
Account acct;
public StandardControllerExtension (ApexPages.standardController std)
{
acct = (Account)std.getRecord();
}
public List<Opportunity> getChildOpps() {
return [Select Name, Amount, StageName, CloseDate From Opportunity
Where AccountId = :acct.Id
and (IsWon = true or IsClosed = false)];
}
private void createTaskOnChildOpps () {
List<Task> tasksToInsert = new List<Task> ();
for (Opportunity opp : childOpps) {
if (!opp.isClosed) {
tasksToInsert.add (
new Task(
WhatId = Opp.Id,
OwnerId = opp.OwnerId,
ActivityDate =Date.today () + 3,
Status = 'Not Started',
Subject = 'Send follow-up email to pirmary contact'
)
);
}
}
if (tasksToInsert.size() >0 )insert taskToInsert;
}
public PageReference save() {
if (acct.Rating =='Hot') {
createTaskOnChildOpps();
}
update acct;
return new PageReference ('/' + acct.Id);
}
}
can anyone help me with this ?
Error: Compile Error: Variable does not exist: childOpps at line 14 column 23
public class StandardControllerExtension {
Account acct;
public StandardControllerExtension (ApexPages.standardController std)
{
acct = (Account)std.getRecord();
}
public List<Opportunity> getChildOpps() {
return [Select Name, Amount, StageName, CloseDate From Opportunity
Where AccountId = :acct.Id
and (IsWon = true or IsClosed = false)];
}
private void createTaskOnChildOpps () {
List<Task> tasksToInsert = new List<Task> ();
for (Opportunity opp : childOpps) {
if (!opp.isClosed) {
tasksToInsert.add (
new Task(
WhatId = Opp.Id,
OwnerId = opp.OwnerId,
ActivityDate =Date.today () + 3,
Status = 'Not Started',
Subject = 'Send follow-up email to pirmary contact'
)
);
}
}
if (tasksToInsert.size() >0 )insert taskToInsert;
}
public PageReference save() {
if (acct.Rating =='Hot') {
createTaskOnChildOpps();
}
update acct;
return new PageReference ('/' + acct.Id);
}
}
can anyone help me with this ?
Account acct;
List<Opportunity> ChildOpps ;
public StandardControllerExtension (ApexPages.standardController std)
{
acct = (Account)std.getRecord();
}
public List<Opportunity> getChildOpps()
{
ChildOpps = [Select Name, Amount, StageName, CloseDate From Opportunity Where AccountId = :acct.Id and (IsWon = true or IsClosed = false)];
return ChildOpps;
}
private void createTaskOnChildOpps () {
List<Task> tasksToInsert = new List<Task> ();
for (Opportunity opp : childOpps) {
if (!opp.isClosed) {
tasksToInsert.add (
new Task(
WhatId = Opp.Id,
OwnerId = opp.OwnerId,
ActivityDate =Date.today () + 3,
Status = 'Not Started',
Subject = 'Send follow-up email to pirmary contact'
)
);
}
}
if (tasksToInsert.size() >0 )insert taskToInsert;
}
public PageReference save() {
if (acct.Rating =='Hot') {
createTaskOnChildOpps();
}
update acct;
return new PageReference ('/' + acct.Id);
}
}
All Answers
Include this below line in the variable decaration.
list<Opportunity> ChildOpps=new list<Opportunity>();
Then it will work.
List<Opportunity> ChildOpps;
public List<Opportunity> getChildOpps()
{
ChildOpps = [Select Name, Amount, StageName, CloseDate From Opportunity Where AccountId = :acct.Id and (IsWon = true or IsClosed = false)];
return ChildOpps;
}
You could also directly call your getChildOpps method in createTaskOnChildOpps, but I wouldn't recommend it. You might end up with a different list of Opportunities than the page originally started with.
list<Opportunity> ChildOpps=new list<Opportunity>();
because its the first time writing such a long code !
Account acct;
List<Opportunity> ChildOpps ;
public StandardControllerExtension (ApexPages.standardController std)
{
acct = (Account)std.getRecord();
}
public List<Opportunity> getChildOpps()
{
ChildOpps = [Select Name, Amount, StageName, CloseDate From Opportunity Where AccountId = :acct.Id and (IsWon = true or IsClosed = false)];
return ChildOpps;
}
private void createTaskOnChildOpps () {
List<Task> tasksToInsert = new List<Task> ();
for (Opportunity opp : childOpps) {
if (!opp.isClosed) {
tasksToInsert.add (
new Task(
WhatId = Opp.Id,
OwnerId = opp.OwnerId,
ActivityDate =Date.today () + 3,
Status = 'Not Started',
Subject = 'Send follow-up email to pirmary contact'
)
);
}
}
if (tasksToInsert.size() >0 )insert taskToInsert;
}
public PageReference save() {
if (acct.Rating =='Hot') {
createTaskOnChildOpps();
}
update acct;
return new PageReference ('/' + acct.Id);
}
}