• Oleg Lavvrynenko
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I have such Visualforce code
<apex:page controller="MyController">
       <apex:PageBlock title="My Page Block">
      <apex:form >
              <apex:selectList value="{!Consultant}" multiselect="true">
                    <apex:actionSupport event="onchange" 
                    reRender="TaskBlock"/>
                  <apex:selectOptions value="{!Consultants}"></apex:selectOptions>
              </apex:selectList>
              </apex:form>
       </apex:PageBlock>
       <apex:form >
<apex:pageBlock title="Our Products" id="TaskBlock" >
  <apex:pageBlockSection columns="1">
     <apex:pageBlockTable value="{!tasks}" var="pitem" >
           <apex:column headerValue="Task Name">
                  <apex:outputText value="{!pitem.name}"/>
           </apex:column>
         <apex:column headerValue="Consultant">
             <apex:outputField value="{!pitem.Consultant__c}"/>
         </apex:column>
      </apex:pageBlockTable>
    </apex:pageBlockSection>
   </apex:pageBlock>
</apex:form>
    </apex:page>

After selection  some option, relate tasks should  appear in table.
butt it doesn't work with such controller
 
public class MyController {

 
    public String Consultant { get; set; }
     public String Consultants { get; set; }
    public List<task__c> consultList{ get; set; }
    public String[] names { get; set; }
    public List<Task__c> pitem;
public MyController()
{

}
public void setConsultant(Id value) {
 pitem = [Select name,consultant__c from task__c WHERE 
consultant__c in (SELECT id FROM contact WHERE name= 'Kristy Doherty') ];
    System.Debug('In 1'); }
 


//public void setConsultants(){}

public  Set<SelectOption> getConsultants() {
         consultList = [Select consultant__c,consultant__r.name from task__c];
        Set<SelectOption> options = new Set<SelectOption>();
        System.debug(consultList.size());
         for(integer i=0;i<consultList.size();i++)
         {
         if (consultList[i].consultant__r.name != null)
         options.add(new SelectOption(consultList[i].consultant__r.name , consultList[i].consultant__r.name  ));
         }         
         return options;        
   }

public List<task__c> getTasks() {return pitem;}
public void setTasks(Id value) {

        pitem = [Select name,consultant__c from task__c WHERE 
consultant__c in (SELECT id FROM contact WHERE name=: value) ];
                System.Debug(value);  
                 
   }
   }
How can I fix it?


 
I started to write my first trigger at Apex, but surprisingly get such error after inserting data in Opportunities tab:
Apex trigger AddProject caused an unexpected exception, contact your administrator: AddProject: execution of AfterInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Account: Trigger.AddProject
Here iis  my code:
trigger AddProject on Opportunity (after update,after insert) {
List<Project__c> insertList = new List<Project__c>();
  for (Opportunity opp : 
 [SELECT Name,OwnerId,Description,Id,AccountiD FROM Opportunity WHERE Probability>=0.8 
  AND Id IN :Trigger.New] )
{
  Project__c pr;
  try
  {
   pr=[SELECT Name FROM Project__c WHERE Opportunity_MDR__r.Id=:opp.Id LIMIT 1];
  }
 catch (Exception e)
  {}
  if (pr==null)
  {
  Project__c newProject=new Project__c(Name = opp.Name, OwnerId__c = opp.OwnerId,
  Description__c = opp.Description, Opportunity_MDR__c = opp.Id,Primary_contact__c =opp.Account.Primary_Contact__c);
  insertList.add(newProject);
  // opp.Project_c=newProject;
 System.debug('what a success');
  }
}
try
{
if (insertList!=null)
insert insertList;
}  catch (Exception e) 
 {
  System.debug('Unexpected error has happened  '+ e.getMessage());
 }
}
How can I fix this problemm?
 
I have such Visualforce code
<apex:page controller="MyController">
       <apex:PageBlock title="My Page Block">
      <apex:form >
              <apex:selectList value="{!Consultant}" multiselect="true">
                    <apex:actionSupport event="onchange" 
                    reRender="TaskBlock"/>
                  <apex:selectOptions value="{!Consultants}"></apex:selectOptions>
              </apex:selectList>
              </apex:form>
       </apex:PageBlock>
       <apex:form >
<apex:pageBlock title="Our Products" id="TaskBlock" >
  <apex:pageBlockSection columns="1">
     <apex:pageBlockTable value="{!tasks}" var="pitem" >
           <apex:column headerValue="Task Name">
                  <apex:outputText value="{!pitem.name}"/>
           </apex:column>
         <apex:column headerValue="Consultant">
             <apex:outputField value="{!pitem.Consultant__c}"/>
         </apex:column>
      </apex:pageBlockTable>
    </apex:pageBlockSection>
   </apex:pageBlock>
</apex:form>
    </apex:page>

After selection  some option, relate tasks should  appear in table.
butt it doesn't work with such controller
 
public class MyController {

 
    public String Consultant { get; set; }
     public String Consultants { get; set; }
    public List<task__c> consultList{ get; set; }
    public String[] names { get; set; }
    public List<Task__c> pitem;
public MyController()
{

}
public void setConsultant(Id value) {
 pitem = [Select name,consultant__c from task__c WHERE 
consultant__c in (SELECT id FROM contact WHERE name= 'Kristy Doherty') ];
    System.Debug('In 1'); }
 


//public void setConsultants(){}

public  Set<SelectOption> getConsultants() {
         consultList = [Select consultant__c,consultant__r.name from task__c];
        Set<SelectOption> options = new Set<SelectOption>();
        System.debug(consultList.size());
         for(integer i=0;i<consultList.size();i++)
         {
         if (consultList[i].consultant__r.name != null)
         options.add(new SelectOption(consultList[i].consultant__r.name , consultList[i].consultant__r.name  ));
         }         
         return options;        
   }

public List<task__c> getTasks() {return pitem;}
public void setTasks(Id value) {

        pitem = [Select name,consultant__c from task__c WHERE 
consultant__c in (SELECT id FROM contact WHERE name=: value) ];
                System.Debug(value);  
                 
   }
   }
How can I fix it?


 
I started to write my first trigger at Apex, but surprisingly get such error after inserting data in Opportunities tab:
Apex trigger AddProject caused an unexpected exception, contact your administrator: AddProject: execution of AfterInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Account: Trigger.AddProject
Here iis  my code:
trigger AddProject on Opportunity (after update,after insert) {
List<Project__c> insertList = new List<Project__c>();
  for (Opportunity opp : 
 [SELECT Name,OwnerId,Description,Id,AccountiD FROM Opportunity WHERE Probability>=0.8 
  AND Id IN :Trigger.New] )
{
  Project__c pr;
  try
  {
   pr=[SELECT Name FROM Project__c WHERE Opportunity_MDR__r.Id=:opp.Id LIMIT 1];
  }
 catch (Exception e)
  {}
  if (pr==null)
  {
  Project__c newProject=new Project__c(Name = opp.Name, OwnerId__c = opp.OwnerId,
  Description__c = opp.Description, Opportunity_MDR__c = opp.Id,Primary_contact__c =opp.Account.Primary_Contact__c);
  insertList.add(newProject);
  // opp.Project_c=newProject;
 System.debug('what a success');
  }
}
try
{
if (insertList!=null)
insert insertList;
}  catch (Exception e) 
 {
  System.debug('Unexpected error has happened  '+ e.getMessage());
 }
}
How can I fix this problemm?