• bela
  • NEWBIE
  • 100 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 37
    Replies

Hi All,

I have list of candidates  for batch.so I have to assign task to them.for giving task,I have to select the students and once click continue,task should be assigned to selected candidates. and should show only remaining unselected students,so that we can assign task to remaining students.

I am able to do this but once selected one student and task is inserted for that student and next i select another student and trying to insert,The task is assigning to first student which i selected previously and inserting again.means the list is not cleared .can any one help me in this .below is my code.

/*****Apex code:
===========
public class taskrepeat {

public task__c t{set;get;}

public list<task__c> ttt{set;get;}


public list<opportunity__c> OppList{set;get;}

public list<opportunity__c> Oppclear{set;get;}


public list<batch__c > Batch  {set;get;}

public boolean studentshow {set;get;}

public list<studentwrapper> stwrap{set;get;}

public list<studentwrapper> stwrap11{set;get;}


public list<studentwrapper> falselist{set;get;}

public list<studentwrapper> olist{set;get;}
public map<id,opportunity__c> mapopp {set;get;}
public boolean wrapcheckbox{set;get;}

public boolean wrapfalse{set;get;}

public boolean taskshow{set;get;}

public taskrepeat(){

falselist = new list<studentwrapper>();

        stwrap = new list<studentwrapper>();


taskshow=true;
    
Batch  = [select id,name,Course_Detail__c,Status__c,End_Date__c,Course_Detail__r.id,Course_Detail__r.name from batch__c where id ='a0KO0000007Kq1jMAC'];

t = new task__c();

wrapfalse =false;
}

    public pagereference studentlist(){
        stwrap = new list<studentwrapper>();

        OppList = [select id ,name,Course_Detail__c,Course_Detail__r.name,Contact__c,Batch__r.Name,Contact__r.name,Batch__r.id,Batch__c from opportunity__c where batch__r.id  ='a0KO0000007Kq1jMAC'];

        for(opportunity__c o : OppList){
            wrapcheckbox=false;
            stwrap.add(new studentwrapper(o,wrapcheckbox));
        }

        studentshow = true;
        wrapfalse =false;
taskshow=false;

        return null;
    }

    public void assigntask(){
    
        ttt = new list<task__C>();
              falselist = new list<studentwrapper>();

        mapopp = new map<id,opportunity__c>();
                    olist = new list<studentwrapper>();
                    
                     Oppclear = new list<opportunity__c>();

        for(studentwrapper aw  : stwrap){
                     // stwrap = new list<studentwrapper>();

           if(aw.check == true ){
           
                   mapopp.put(aw.oppwrap.id , aw.oppwrap);

               
               Task__c tr = new Task__c();
               
               tr.name=t.name;
     
               tr.Batch__c = aw.oppwrap.Batch__r.id;
               
     
               tr.Student__c = aw.oppwrap.Contact__r.id ;
     
    
              ttt.add(tr);
              
              
           }
           
          if(aw.check == false){

           falselist.add(aw);

           wrapfalse =true;

           studentshow = false;
        
           taskshow=false;

           }  
         

     }
     
    
     

   insert ttt;
//remove();
        /*stwrap = new list<studentwrapper>();

 for (integer i = 0; i < stwrap.size(); i++){
     if(stwrap[i].check == true){
    stwrap[i] = null; 
    }
    }*/
     
   //stwrap.clear(olist);
   
   //studentnotselected();
    }
    
   public void remove(){
   
   stwrap = new list<studentwrapper>();

 for (integer i = 0; i < stwrap.size(); i++){
     if(stwrap[i].check == true){
    stwrap[i] = null; 
    }
    }
   
   }

    /*public void studentnotselected(){
    
            ttt = new list<task__C>();

        mapopp = new map<id,list<opportunity__c>>();
                    olist = new list<opportunity__c>();

       falselist = new list<studentwrapper>();


        for(studentwrapper aw  : stwrap){

           if(aw.check == false){
       
           falselist.add(aw);
           }

        }
        
             //     olist.clear();

        wrapfalse =true;

        studentshow = false;
taskshow=false;

    }*/



public class studentwrapper{
    public opportunity__c oppwrap{set;get;}
    public boolean check {set;get;}

    public studentwrapper(opportunity__c at, boolean c){

    oppwrap=at;

    check=c;
    }

}



}


visualforce
=============
<apex:page controller="taskrepeat">

<apex:pageBlock >

<apex:pageBlockSection >
<apex:pageBlockTable value="{!stwrap}" var="fa" >
<apex:column >
<apex:inputCheckbox value="{!fa.check}"/>
</apex:column>
<apex:column value="{!fa.oppwrap.name}"/>

<apex:column />

</apex:pageBlockTable>

</apex:pageBlockSection>
 <apex:commandButton value="continue" action="{!taskassign}" id="aa" onclick="if(!confirm('Do you want to continue?')){return false};"/>

</apex:pageBlock>-->
<!--<apex:pageBlock rendered="{!taskshow}" >
<apex:pageBlockSection >
<apex:inputField value="{!t.name}"/>
<apex:inputField value="{!t.Start_Date__c}"/>
<apex:inputField value="{!t.End_Date__c}"/>
<apex:inputField value="{!t.Description__c}"/>


</apex:pageBlockSection>
<apex:commandButton value="Next" action="{!studentlist}"/>
</apex:pageBlock>

<apex:pageBlock rendered="{!studentshow}">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!stwrap}" var="op">
<apex:column >
<apex:inputCheckbox value="{!op.check}"/>
</apex:column>
<apex:column value="{!op.oppwrap.name}"/>
</apex:pageBlockTable>
 </apex:pageBlockSection>
 <apex:commandButton value="continue" action="{!assigntask}" id="aa" onclick="if(!confirm('Do you want to continue?')){return false};"/>
</apex:pageBlock>

<apex:pageBlock rendered="{!wrapfalse}">

<apex:pageBlockSection >
<apex:pageBlockTable value="{!falselist}" var="fa" >
<apex:column >
<apex:inputCheckbox value="{!fa.check}"/>
</apex:column>
<apex:column value="{!fa.oppwrap.name}"/>

<apex:column />

</apex:pageBlockTable>

</apex:pageBlockSection>
 <apex:commandButton value="continue" action="{!assigntask}" id="aa" onclick="if(!confirm('Do you want to continue?')){return false};"/>

</apex:pageBlock>
</apex:page>

  • March 25, 2017
  • Like
  • 0
Hi,
I want to display batch classes status__c (status__C=In Progress,complete,cancelled.....) of particular batch__C of student in piechart,suppose if student has  4 batches,I have to display piechart for single batch and its status__C of batchclass object.but i am not able to repeat it,Instead I am getting all batches batchclasses status in single piechart.below is my code,can anyone helpme to solve it.

controller:
=========


public class facultydatadashboard {

public class facultydatadashboard {

public list<Faculty__c> faculty{set;get;}

public list<Batch__c> batchlist{set;get;}

public list<Batch_Class__c> batchclass{set;get;}
public list<Task__c> tasklist{set;get;}


public list<string> batchesId{set;get;}

public list<facultywrapper> facultywrapperpiechart{set;get;}
public list<facultywrapper> facultywrapperpiechart1{set;get;}
public list<facultywrapper> facultywrapperpieconstruct{set;get;}

public list<Batch_Class__c> bcllist{set;get;}

public map<id,Batch__c> batchmap{set;get;}

public facultydatadashboard(){

batchesId = new list<string>();
batchmap = new map<id,Batch__c>();

batchlist = [select id,name,Faculty__c,Faculty__r.name from Batch__c where Faculty__c='a06O000000aXV1k'];

    for(Batch__c b : batchlist){
        batchesId.add(b.id);
        batchmap.put(b.id,b);
        

       
       
    }
    
    batchclass = [select id,name,Status__c,Batch__c,Batch__r.name from Batch_Class__c where Batch__c = :batchesId];
    
    
tasklist = [select id,name,Faculty__c,Faculty__r.name,status__c from Task__c where Batch__c = :batchesId];
    




   
  
  
  

}

public list<batch__c> getbatch(){
    facultywrapperpiechart = new list<facultywrapper>();

batchlist = [select id,name,Faculty__c,Faculty__r.name from Batch__c where Faculty__c='a06O000000aXV1k'];

return batchlist ;
}

/*public list<facultywrapper> getbatchcla(){

return null;
}*/

public list<facultywrapper> getbatchclasschartofbatch(){

map<id,list<Batch_Class__c>> batchclasschart = new map<id,list<Batch_Class__c>>();
    facultywrapperpiechart1 = new list<facultywrapper>();


for(Batch_Class__c bbb : batchclass){

    if(batchclasschart.get(bbb.batch__c) == null){
         list<Batch_Class__c> b = new list<Batch_Class__c>(); 

     b.add(bbb);
     batchclasschart.put(bbb.batch__c,b);
    }
    else{
           list<Batch_Class__c> b1 = new list<Batch_Class__c>(); 
           b1=batchclasschart.get(bbb.batch__c);
           b1.add(bbb);
           batchclasschart.put(bbb.batch__c,b1);

    }
    
}

 set<id> b11 = new set<id>(); 
b11= batchclasschart.keyset();


for(Id batchid : b11){
system.debug('batchid '+batchid );



bcllist = batchclasschart.get(batchid);

system.debug('bcllist'+bcllist );

for(Batch_Class__c bcccl:bcllist ){
system.debug('bcccl'+bcccl);

        facultywrapperpiechart1.add(new facultywrapper(bcccl.status__c,batchclasschart.get(bcccl.batch__c).size(),bcccl.batch__r.name));
        }

}





 
 
return facultywrapperpiechart1;
}




public class facultywrapper{

public string name{set;get;}
public decimal data{set;get;}
public Batch_Class__c bc{set;get;}
public string batchname{set;get;}

//-------------



public facultywrapper(string n,decimal d,string bn){

this.name = n;
this.data= d;
this.batchname=bn;







 
 

}






}




-----------------------------

<apex:page controller="facultydatadashboard">
 
    
    batchclasschartofbatch
    <apex:repeat value="{!batchclasschartofbatch}">
        <apex:chart height="250" width="450" data="{!batchclasschartofbatch}" > 
            <apex:pieSeries tips="true" dataField="data" labelField="name"/> 

            <apex:legend position="bottom"/>
        </apex:chart>

</apex:repeat>
</apex:page>

 
  • March 15, 2017
  • Like
  • 0
please help its urgent,on click of generatePDF button on opportunity ,I am trying to display the fields of  account and its contacts(not opportunities of only contact) of that oportunity on the pdf page,I am able to display record of account related to opportunity,but i  am not able to get and display that accounts related contacts.Please help me in this scenario.below is code.

Unable to query the contacts of account of the opportunity(please help)

Controller:
--------------
public with sharing class diplayacccontofopp {
public list<opportunity> opp{set;get;}
public list<contact> oppcon{set;get;}
public list<contact> con{set;get;}
public list<account> acc{set;get;}

    public diplayacccontofopp(ApexPages.StandardController controller) {
    Id OppotunityIDs = ApexPages.currentPage().getParameters().get('Id');
    map<id,account> mo=new map<id,account>([select id,name  From account]);  
        
        
       // opp=[select id, name,account.id,account.name from opportunity where id =:OppotunityIDs ];
       //acc= [select id,Name,(select id,FirstName,LastName FROM Contacts ) From Account where id =:opp[0].id];
       
    opp = [select id,AccountId,account.id,account.name  From Opportunity WHERE Id=:OppotunityIDs ];
    acc=[select id, Name,(Select name,id From Opportunities where id=:OppotunityIDs) from Account ];
    
 oppcon=[SELECT Id, Name,firstname FROM contact where accountId=:acc[0].id];   
    }

}

VF page:
---------------
<apex:page standardController="opportunity" extensions="diplayacccontofopp" renderAs="PDF">
<table width="100%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;"
        cellpadding="5">
        <tr>
            <td colspan="4" style="font-size: x-large;">
                Opportunity Info
            </td>
        </tr>
        <tr>
            <td colspan="2" >
                {!Opportunity.Name}
            </td>
        </tr>
        <tr>
            <td colspan="15">
            </td>
        </tr>
        
        <tr>
            <td colspan="4" style="font-size: x-large;">
            ACCOUNT INFO
            </td>
        </tr>
        
        <apex:repeat value="{!opp}" var="op">
                <tr id="{!op.account.Id}">
                    <td>
                        {!op.account.name}
                    </td>
                </tr>            
        </apex:repeat>
        
        
      
          
            
       </table>
       
            
    <!--<table>
  <apex:repeat value="{!acc}" var="a">
    <tr>
      <td></td>
      <apex:repeat value="{!a.Contacts}" var="cont">
         <td><apex:outputText value="{!cont.firstName}"/></td>
      </apex:repeat>
    </tr>
  </apex:repeat>
  
</table>-->
       
    <table>   
   <apex:repeat value="{!oppcon}" var="a">
    <tr>
      <td></td>
      <apex:repeat value="{!a.Id}" var="cont">
         <td><apex:outputText value="{!a.firstname}"/></td>
      </apex:repeat>
    </tr>
  </apex:repeat>
            </table>


</apex:page>

Thanks,
B.Mahanandeesh.
  • December 30, 2016
  • Like
  • 0
I am trying to display the seach with pagination by using standard set controller but iam getting below error ,please help where i am going wrong and is the approch is correct?
System.NullPointerException: Attempt to de-reference a null object 
Class.Pagnationwithsetcontroller.getOpportunities: line 50, column 1


VF Page
----------------
<apex:page controller="Pagnationwithsetcontroller">
   <apex:form >
    <apex:pageBlock id="a" >
     <apex:pageBlockSection >
      <apex:inputText value="{!InputString}" title="Search" label="search" >
       <apex:actionSupport action="{!lstofopportunity}" event="onchange" reRender="a" status="status"/> 
      </apex:inputText>
     </apex:pageBlockSection>
     
     <apex:pageBlockSection columns="1">
      <apex:actionStatus id="status" startText="requesting..."/>
       <apex:pageBlockTable value="{!Opportunities}" var="a">
        <apex:column value="{!a.name}"/>
        </apex:pageBlockTable>
        <apex:panelGrid columns="2">
                <apex:commandLink value="first" action="{!first}"/>
                <apex:commandLink value="first" action="{!last}"/>
        </apex:panelGrid>
     </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>

Controller:
----------------
public with sharing class Pagnationwithsetcontroller {
  Public string giveninputString;
  public integer size=2;
  //takes the letter which we type in the input text
  public void setInputString(string s){
   giveninputString=s;
   system.debug('hiiii1 SET'+giveninputString);
  }
  //The "get" method is used to pass data from your Apex code to your Visualforce page
  public string getInputString(){
    system.debug('hiiii2 GET'+giveninputString);
    return null;
  }
  
  public List<opportunity> oppresults{set;get;}
  
  public List<opportunity> getoppresults() {
    system.debug('hiiii oppresults in getoppresults '+oppresults);
    return oppresults;
  }
  
  public  pageReference lstofopportunity(){
    oppresults=(list<opportunity>)[find :giveninputString in all Fields returning opportunity(name)][0] ;
    system.debug('hiiii in lstofopportunity'+oppresults);
    //con= new ApexPages.StandardSetController(oppresults); 
                                                     //system.debug('aaaa11111111111'+con);

    //con.setPageSize(size);
    return null;
  }
 
public ApexPages.StandardSetController con{get; set;} 

Apexpages.standardSetController setcon{get 
                                          {

                                           if(setcon==null){
                                                 system.debug('asassasaasaas'+oppresults);
                                             setcon = new Apexpages.standardsetController(oppresults);
                                                 system.debug('aaaa11111111111'+setcon );

                                             setcon.setPageSize(size);
                                           }return setcon;
                                          }
                                        set;
                                      } 
                                       
public List<Opportunity> getOpportunities() {
               
         return (list<opportunity>)Con.getRecords();
    } 

public void first(){
con.first();
}  
public void last(){
con.last();

  
}
 
  • December 21, 2016
  • Like
  • 0
I tried in below way,but i am getting this error  execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.addoppamount: line 18, column 1 and also getting another error at line 16 line ,can any one explain where i did mistake.

trigger addoppamount  on opportunity(after update,after insert) {
   set<id> s=new set<id>();
       for (opportunity op:trigger.new){
     s.add(op.accountid);
    }
    
   map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);

    for(opportunity opp:trigger.new){
    Account acc = new Account();
    acc.id=ma.get(opp.accountid).id;
    list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities)  from account where id =: acc.id];
    system.debug('hiiiiiii'+af);
        for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
        {
        acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error 
            system.debug('hiiiiiii'+acc.total_opportunity_amount__c);

        }
        update acc;
    } 
  • December 02, 2016
  • Like
  • 0
can any one help me in this trigger,I am writting a trigger,which is displaying amount of opportunities of account in account field.I tried in below way,but i am getting this error  execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.addoppamount: line 18, column 1 and also getting another error at line 16 line ,can any one explain where i did mistake
trigger addoppamount  on opportunity(after update,after insert) {
   set<id> s=new set<id>();
       for (opportunity op:trigger.new){
     s.add(op.accountid);
    }
    
   map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);

    for(opportunity opp:trigger.new){
    Account acc = new Account();
    acc.id=ma.get(opp.accountid).id;
    list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities)  from account where id =: acc.id];
    system.debug('hiiiiiii'+af);
        for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
        {
        acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error 
            system.debug('hiiiiiii'+acc.total_opportunity_amount__c);

        }
        update acc;
    }

    
    
      
}
  • December 01, 2016
  • Like
  • 0
I created a hirarviewcontrollers where when a role is selected it should display its child roles(getSearchRole()).but I am not knowing how to display child roles when role is selected.Please help me in solving the problem.Below is the code.

Controller:
public with sharing class hirarviewcontrollers {
  public Map<id,UserRole> roleUsersMap{get;set;}
    public Map<id,List<UserRole>> parentChildRoleMap{get;set;}

              public List<UserRole> tempList{set;get;}
                            public List<UserRole> displayList{set;get;}


public List<user> allSubordinates{get;set;}
   
   
    public hirarviewcontrollers(ApexPages.StandardController controller) {
    
    selectedRole='';
    }
    
    public string selectedRole{get;set;}
    public List<Userrole> roleLst{get;set;}
        public List<Userrole> roleLstopt{get;set;}

    public Pagereference getSearchRole(){
    roleLst=new List<Userrole>([select developername,id,name,ParentRoleID from userrole where name like:'%'+selectedRole+'%' order by parentRoleId ]);
    
    // Create a blank list
        allSubordinates = new List<User>();
        
        // Get role to users mapping in a map with key as role id
        roleUsersMap = new Map<Id, UserRole>([select Id, Name, parentRoleId, (select id, name from users) from UserRole order by parentRoleId]);
        
        // populate parent role - child roles map
        parentChildRoleMap = new Map <Id, List<UserRole>>();        
        for (UserRole r : roleUsersMap.values()) {
            if (!parentChildRoleMap.containsKey(r.parentRoleId)){
                tempList = new List<UserRole>();
                tempList.Add(r);
                parentChildRoleMap.put(r.parentRoleId, tempList);
               for(integer i=0;i<parentChildRoleMap.size();i++){   //As it is displaying one filed on vf, I used for loop but not working, as i new to code,I am confused with map.please help me
              displayList=  (List<UserRole>)parentChildRoleMap.get(r[i].parentRoleId);
              }

            }
            else {
                tempList = (List<UserRole>)parentChildRoleMap.get(r.parentRoleId);
                tempList.add(r);
                parentChildRoleMap.put(r.parentRoleId, tempList);
            }
        }
   // [select Id,name from UserRole where ParentRoleId  = :UserRole AND ParentRoleID != null]
    return null;
    
    }
    
 public List<SelectOption> getRoles()
{
  List<SelectOption> options = new List<SelectOption>();
      roleLstopt=new List<Userrole>([select developername,id,name,ParentRoleID from userrole]);

  options.add(new SelectOption('--None--','--None--'));
  for (Integer j=0;j<roleLstopt.size();j++)
  {
      options.add(new SelectOption(roleLstopt[j].name,roleLstopt[j].name));
  }
  return options;
}
}

VF Page:

<apex:page standardcontroller="UserRole" extensions="hirarviewcontrollers">
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!selectedRole}" multiselect="false" size="1" >
  <apex:actionSupport event="onchange" reRender="a" action="{!getSearchRole}" />
<apex:selectOptions value="{!Roles}"/>
        </apex:selectList><p/> 
 <!--<apex:selectList value="{!selectedRole}" multiselect="false" size="1" >
               <apex:actionSupport event="onchange" reRender="a" />

            <apex:selectOptions value="{!citynames}"/>
        </apex:selectList><p/> -->
<!--<apex:outputLabel >Search Role</apex:outputLabel>
<apex:inputText value="{!selectedRole}"/>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" title="Search Role" action="{!getSearchRole}" />
</apex:pageBlockButtons>-->
<apex:pageBlock >
<apex:pageBlockTable value="{!displayList}" var="d">
<apex:column value="{!d.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
<apex:pageBlock id="a">
<apex:pageBlockSection collapsible="false" title="Search Results" columns="1">
<apex:pageBlockTable value="{!roleLst}" var="rolel">
<apex:column headerValue="Rolename" value="{!rolel.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
  • September 21, 2016
  • Like
  • 0
Hi,
I have a scenario where on account we have a field called primarychild text box and in contacts of account  we have ischild checkbox field,if ischild is checked for one contact and the ischild should be false for remaining contacts of that account  and checked contact lastname should be displayed on account primarychild text box. 
I have tried but I am not able solve it.

As i am new to coding I can able to analyse but not able to implement .here is my code  where i tried to get record of contacts based on account id and for every account I am checking its contacts and if  ischild is updated to true old records should be false. 

trigger checkonecontact on Contact (before update) {

Set<Id> s=new Set<Id>();

for(contact c:trigger.old){
   s.add(c.accountId);
}


Map<id,contact> cmap=new Map <id,contact>([select name,childeligible__c,account.accountchild__c  from contact where accountId in:s]);

for(account a:[select name,accountchild__c from account where id in:s]){
        Contact obj = cmap.get(c.id);


}


}



 
  • June 27, 2016
  • Like
  • 0
I have wrote a trigger that display error if rating ==hot,for this trigger I wrote testclass but I am getting testclass fail showing following error.
and it is also showing other trigger Trigger.updateAccount,why?can anyone help me 

System.AssertException: Assertion Failed: Expected: The Last Name "hot" is not allowed for DML, Actual: updateAccount: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.updateAccount: line 2, column 1

Trigger:
----------
trigger adderror on Account (before delete) {
 
 for(Account acc:trigger.old)
 {
   if(acc.Rating=='hot')
    {
     acc.addError('Account associtated. Cannot delete this record');

    }
 }


testclass
-------------
@isTest
public class TestAddError{

static testMethod void errorMethod(){
Account acccc=new Account(Rating='hot');
Database.saveResult sr= Database.insert(acccc,false);
System.assertEquals('The Last Name "'+acccc.rating+'" is not allowed for DML',sr.getErrors()[0].getMessage());

}

}
}
  • June 04, 2016
  • Like
  • 0
Hi,
I wrote search functionality,In that i want to display no records found if a user gives value that have no records,this i want to display using javascript.not by pagemessages in controller.Below is the code.Please help me as I am new to java script.

VF:
---------------
<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(val){

var inputValue = document.getElementById(val).value;

<!--var inputValue = document.getElementById('one:two:search').value;-->

if(inputValue.length <= 0){
alert('no records found');
}
else{
actionFunName(inputValue);
}
}
</script>
<apex:pageMessages />

<apex:form id="two">
 <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />

<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js('{!$Component.search}')"   />
<!--<apex:inputText value="{!search}"  id="search" />-->
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="two"/>-->

<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
    <apex:pageBlockSection >
       <apex:pageBlockTable value="{!poslis}" var="pl"   >
         <apex:column value="{!pl.name}"/>
       </apex:pageBlockTable> 
    </apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock rendered="{!blockOnEnter}" > 
    <apex:pageBlockSection id="d">
       <apex:pageBlockTable value="{!pos}" var="p"  >
         <apex:column value="{!p.name}"/>
         <apex:column >
         <apex:inputCheckbox value="{!p.name}"/>
         </apex:column>
       </apex:pageBlockTable>
    </apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>

controller:
-------------
public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
        
         blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }


    public String search { get; set; }

public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}

}

Thanks,
Mahanandeesh.
  • May 27, 2016
  • Like
  • 0
Hi,
I wrote search functionality,In that i want to display no records found if a user gives value that have no records,this i want to display using javascript.not by pagemessages in controller.Below is the code.Please help me as I am new to java script.

VF:
---------------
<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(val){

var inputValue = document.getElementById(val).value;

<!--var inputValue = document.getElementById('one:two:search').value;-->

if(inputValue.length <= 0){
alert('no records found');
}
else{
actionFunName(inputValue);
}
}
</script>
<apex:pageMessages />

<apex:form id="two">
 <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />

<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js('{!$Component.search}')"   />
<!--<apex:inputText value="{!search}"  id="search" />-->
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="two"/>-->

<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
    <apex:pageBlockSection >
       <apex:pageBlockTable value="{!poslis}" var="pl"   >
         <apex:column value="{!pl.name}"/>
       </apex:pageBlockTable> 
    </apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock rendered="{!blockOnEnter}" > 
    <apex:pageBlockSection id="d">
       <apex:pageBlockTable value="{!pos}" var="p"  >
         <apex:column value="{!p.name}"/>
         <apex:column >
         <apex:inputCheckbox value="{!p.name}"/>
         </apex:column>
       </apex:pageBlockTable>
    </apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>

controller:
-------------
public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
        
         blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }


    public String search { get; set; }

public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}

}

Thanks,
Mahanandeesh.
 
  • May 26, 2016
  • Like
  • 0
Hi All,

Below is the trigger where when contacts are created, there is field called Count_of_Contacts__c  in account which counts no of contacts and display in account field Count_of_Contacts__c.In this I have a doubt regarding map,Please explain me.  

mapcon.put(c.accountid,listcon.size());//In this line we are putting accountids which are in contact object,to get the size of contacts
mapcon.get(ac.id)​       //in this line we are using account reference and getting id for size,but we have to call like this                      know mapcon.get(c.accountid) to get the size,because we have created map which taking accountids of contact,but how it is taking ac.id which is in account for getting size.



trigger contactcountaccount on Contact (after insert) {
list<Id> listContact = new list<Id>();
list<contact> listcon=new list<contact>();
list<account> listAcc= new list<account>(); 

set<Id> s=new set<Id>();
for(contact c:trigger.new){
s.add(c.accountid);
}

list<account> accountId = [select id,name,Count_of_Contacts__c from account where id in:s];
list<contact> contactId=  [select id,accountid,name from contact where accountid in:s];
map<id,Integer> mapcon=new map<id,Integer>();


for(account A:accountId)
{
for(contact C: contactId){
if(c.accountid==a.id){
listcon.add(c);
system.debug('this are list of contacts if ids are equal'+listcon);
mapcon.put(c.accountid,listcon.size());           //please explain
system.debug('this are map of con accountid and consize '+mapcon);


 }
}
}
if(listcon.size()>0){
for(account ac:accountId){
if(mapcon.get(ac.id)==null){                    //please explain
system.debug('GET account id into map'+mapcon.get(ac.id));

ac.Count_of_Contacts__c =0;
}
else{
ac.Count_of_Contacts__c = mapcon.get(ac.id);
system.debug('getting how many contacts with id'+ac.Count_of_Contacts__c);

}
listAcc.add(ac);
system.debug('final list listAcc'+listAcc);

}

}

if(listAcc.size()>0)
update listAcc

Thanks,
B.Mahanandeesh
  • May 23, 2016
  • Like
  • 0
I wrote a class when record is inserted it is redirected to another page and should display that record as output field.I wrote a test class for first class,but i dont know how to write test class for pagereference and 2nd class.Please help me

class 1(save record)
-----------
public with sharing class saveInputController {
public string positionname{set;get;}
   
   
    public PageReference saveposition() {
    position__c p=new position__c();
     p.name=positionname;
     insert p;
     PageReference posPage = new PageReference('https://c.ap2.visual.force.com/apex/showinput?id=' + p.name);//I didnt covered this in test class .
     posPage.setRedirect(true);
     return posPage;
    }
}
testclass for class one
------------------------------------

@isTest
public class testsaveInputController{

public static testmethod void v1 (){
position__c p= new Position__c(name='maha');
insert p;
position__c p1= new Position__c(name='maha1');
insert p1;
position__c p2= new Position__c(name='maha2');
insert p2;
Test.startTest();
saveInputController sic=new saveInputController ();
PageReference myVfPage =sic.saveposition();
Test.stopTest();
System.assertEquals('maha', myVfPage );
}
}



class2(display as outfield)(I am not knowing how to write testclass for this because of page reference)
--------------------------------------
public with sharing class showinputcontroller {
public List<position__c> p{get;set;}

public showinputcontroller(){
p=[select name from position__c where name like :ApexPages.currentPage().getParameters().get('id') limit 5];
}

}

Thanks,
Mahanandeesh.
  • May 18, 2016
  • Like
  • 1
Hi All,
I am trying to insert record based on the record type.but while trying the the logic is not going into the if condition.and is the write way to take hardcode id for inserting record ?please help me below is the code.

public with sharing class insertinrecordtypecontroller {

public String name { get; set; }
public String value { get; set; }

public PageReference Insertvalue() {
    position__C po=new position__c();
        system.debug('this is insert value 111111111');

    if(po.RecordTypeId =='01228000000Aif1AAC'){
    po.name=name;
    po.value__c=value;
    system.debug('this is insert value');
    insert po;
    }
    return null;
  }
}


visual force:
=----------------

<apex:page controller="insertinrecordtypecontroller">
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockSection >
 <apex:inputText label="name" value="{!name}" />

<apex:inputText label="value" value="{!value}" />
</apex:pageBlockSection>

 </apex:pageBlock> 
 <apex:commandButton value="save" action="{!Insertvalue}"/>

 </apex:form>
</apex:page>


Thanks,
B.Mahanandeesh.
  • May 15, 2016
  • Like
  • 0
can any one please,help to solve below problem regarding java script for the below code

I am checking database value  in java script [controller:  pos=Database.query(holdString);] when pos contains letter which dont have records ,it should display no records found (eg: if letter x is entered it should display no records found if there are no records with X),i am trying as i mentioned above in script but i think its not the write way,this i achived through controller, but i want this validation  through javascript, please help me.


as i am new to javascript,pls help me to understand.


<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(value){
var inputValue = document.getElementById(search).value;
alert(inputValue );
if(inputValue==null||inputValue==''){
alert('no records found');
}
else{
actionFunName();
}
}
</script>


<apex:form id="two">
       <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js(value)"   />
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="one:two:block1"/>-->
<apex:outputText id="error" value="{!error}" />
<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl"   >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable> 
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!blockOnEnter}" > 
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p"  >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>


controller
---------------

public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
       blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }
public String search { get; set; }
public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}
}
  • May 10, 2016
  • Like
  • 0
Hi ,
regarding js in vf i have doubts in below code.pls help me.

1.function js(value)
   <apex:inputText value="{!search}"  id="search" onkeyup="js(value)"   />
   I used parameterized method but the above code is working even i remove parameter value,Is the declaration is correct and when to use parameterized method,because i used as the method returns a value in inputtext through this parameter.Is it correct,if not correct me


2.I am checking database value  in java script [controller:  pos=Database.query(holdString);] when pos contains letter which dont have records ,it should display no records found ,i am trying as i mentioned above in script but i think its not the write way,this i achived through controller, but i want this validation  through javascript 

as i am new to javascript,pls help me to understand.


<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(value){
var inputValue = document.getElementById(search).value;
alert(inputValue );
if(inputValue==null||inputValue==''){
alert('no records found');
}
else{
actionFunName();
}
}
</script>


<apex:form id="two">
       <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js(value)"   />
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="one:two:block1"/>-->
<apex:outputText id="error" value="{!error}" />
<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl"   >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable> 
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!blockOnEnter}" > 
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p"  >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>


controller
---------------

public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
       blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }
public String search { get; set; }
public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}
}



 
  • May 09, 2016
  • Like
  • 0
i have wrote a small batch class to update all records as rating =warm,but it is showing Error: Compile Error: Variable does not exist: rating at line 13 column 5 .I am not getting what mistake i did.please help me 

global class SearchAndReplace implements Database.Batchable<sObject>{

global database.querylocator start(database.BatchableContext Bc){
return database.getQueryLocator([select id,name,rating from account]);
}

global  void execute(database.batchableContext bc,list<account> scope){
   for(account a:scope){
    a.rating='warm';
 }
update scope;     
}

global void finish(database.batchablecontext bc){

}

}
  • May 09, 2016
  • Like
  • 0
I wrote a search functionality,i want to show a message "no records found" when there are no records on the entered letter
through a javascript,i got through pagemessage,but i want  through javascript.I tied but its not working,can u please help me regarding this.

<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(value){
var inputValue = document.getElementById(search).value;
alert(inputValue );
if(inputValue==null||inputValue==''){
alert('no records found');
}
else{
actionFunName();
}
}
</script>

<apex:form id="two">
       <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js(value)"   />
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="one:two:block1"/>-->
<apex:outputText id="error" value="{!error}" />
<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl"   >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable> 
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!blockOnEnter}" > 
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p"  >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>


controller
---------------

public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
       blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }
public String search { get; set; }
public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}
}
  • May 02, 2016
  • Like
  • 0
I am performing custom search functionality on position__c object,I am using rendering ,when the key is on it is refreshing whole page ,so when i use rerendered on action status, action status is not working  
this is my code pls help me

<apex:page controller="searchwithactionstatuscontroller" >
<apex:form >
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"  />
<apex:inputText value="{!search}"  id="search" />
<apex:actionSupport event="onkeyup" action="{!searchpositions}"  rerendered="block2"/>
<apex:outputText id="error" value="{!error}" />

<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl"   >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable> 
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock rendered="{!blockOnEnter}" id="block2" > 
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p"  >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>


</apex:column>

</apex:pageBlockTable>
</apex:pageBlockSection>
 
</apex:pageBlock> 
</apex:form>
</apex:page>

controller
----------------

public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
        if(pos!=null && pos.size() ==0){
        error ='no records found';
         } 
        
        blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }


    public String search { get; set; }

public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}



}
  • April 23, 2016
  • Like
  • 0
I wrote a class when record is inserted it is redirected to another page and should display that record as output field.I wrote a test class for first class,but i dont know how to write test class for pagereference and 2nd class.Please help me

class 1(save record)
-----------
public with sharing class saveInputController {
public string positionname{set;get;}
   
   
    public PageReference saveposition() {
    position__c p=new position__c();
     p.name=positionname;
     insert p;
     PageReference posPage = new PageReference('https://c.ap2.visual.force.com/apex/showinput?id=' + p.name);//I didnt covered this in test class .
     posPage.setRedirect(true);
     return posPage;
    }
}
testclass for class one
------------------------------------

@isTest
public class testsaveInputController{

public static testmethod void v1 (){
position__c p= new Position__c(name='maha');
insert p;
position__c p1= new Position__c(name='maha1');
insert p1;
position__c p2= new Position__c(name='maha2');
insert p2;
Test.startTest();
saveInputController sic=new saveInputController ();
PageReference myVfPage =sic.saveposition();
Test.stopTest();
System.assertEquals('maha', myVfPage );
}
}



class2(display as outfield)(I am not knowing how to write testclass for this because of page reference)
--------------------------------------
public with sharing class showinputcontroller {
public List<position__c> p{get;set;}

public showinputcontroller(){
p=[select name from position__c where name like :ApexPages.currentPage().getParameters().get('id') limit 5];
}

}

Thanks,
Mahanandeesh.
  • May 18, 2016
  • Like
  • 1
Hi,
I want to display batch classes status__c (status__C=In Progress,complete,cancelled.....) of particular batch__C of student in piechart,suppose if student has  4 batches,I have to display piechart for single batch and its status__C of batchclass object.but i am not able to repeat it,Instead I am getting all batches batchclasses status in single piechart.below is my code,can anyone helpme to solve it.

controller:
=========


public class facultydatadashboard {

public class facultydatadashboard {

public list<Faculty__c> faculty{set;get;}

public list<Batch__c> batchlist{set;get;}

public list<Batch_Class__c> batchclass{set;get;}
public list<Task__c> tasklist{set;get;}


public list<string> batchesId{set;get;}

public list<facultywrapper> facultywrapperpiechart{set;get;}
public list<facultywrapper> facultywrapperpiechart1{set;get;}
public list<facultywrapper> facultywrapperpieconstruct{set;get;}

public list<Batch_Class__c> bcllist{set;get;}

public map<id,Batch__c> batchmap{set;get;}

public facultydatadashboard(){

batchesId = new list<string>();
batchmap = new map<id,Batch__c>();

batchlist = [select id,name,Faculty__c,Faculty__r.name from Batch__c where Faculty__c='a06O000000aXV1k'];

    for(Batch__c b : batchlist){
        batchesId.add(b.id);
        batchmap.put(b.id,b);
        

       
       
    }
    
    batchclass = [select id,name,Status__c,Batch__c,Batch__r.name from Batch_Class__c where Batch__c = :batchesId];
    
    
tasklist = [select id,name,Faculty__c,Faculty__r.name,status__c from Task__c where Batch__c = :batchesId];
    




   
  
  
  

}

public list<batch__c> getbatch(){
    facultywrapperpiechart = new list<facultywrapper>();

batchlist = [select id,name,Faculty__c,Faculty__r.name from Batch__c where Faculty__c='a06O000000aXV1k'];

return batchlist ;
}

/*public list<facultywrapper> getbatchcla(){

return null;
}*/

public list<facultywrapper> getbatchclasschartofbatch(){

map<id,list<Batch_Class__c>> batchclasschart = new map<id,list<Batch_Class__c>>();
    facultywrapperpiechart1 = new list<facultywrapper>();


for(Batch_Class__c bbb : batchclass){

    if(batchclasschart.get(bbb.batch__c) == null){
         list<Batch_Class__c> b = new list<Batch_Class__c>(); 

     b.add(bbb);
     batchclasschart.put(bbb.batch__c,b);
    }
    else{
           list<Batch_Class__c> b1 = new list<Batch_Class__c>(); 
           b1=batchclasschart.get(bbb.batch__c);
           b1.add(bbb);
           batchclasschart.put(bbb.batch__c,b1);

    }
    
}

 set<id> b11 = new set<id>(); 
b11= batchclasschart.keyset();


for(Id batchid : b11){
system.debug('batchid '+batchid );



bcllist = batchclasschart.get(batchid);

system.debug('bcllist'+bcllist );

for(Batch_Class__c bcccl:bcllist ){
system.debug('bcccl'+bcccl);

        facultywrapperpiechart1.add(new facultywrapper(bcccl.status__c,batchclasschart.get(bcccl.batch__c).size(),bcccl.batch__r.name));
        }

}





 
 
return facultywrapperpiechart1;
}




public class facultywrapper{

public string name{set;get;}
public decimal data{set;get;}
public Batch_Class__c bc{set;get;}
public string batchname{set;get;}

//-------------



public facultywrapper(string n,decimal d,string bn){

this.name = n;
this.data= d;
this.batchname=bn;







 
 

}






}




-----------------------------

<apex:page controller="facultydatadashboard">
 
    
    batchclasschartofbatch
    <apex:repeat value="{!batchclasschartofbatch}">
        <apex:chart height="250" width="450" data="{!batchclasschartofbatch}" > 
            <apex:pieSeries tips="true" dataField="data" labelField="name"/> 

            <apex:legend position="bottom"/>
        </apex:chart>

</apex:repeat>
</apex:page>

 
  • March 15, 2017
  • Like
  • 0
I tried in below way,but i am getting this error  execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.addoppamount: line 18, column 1 and also getting another error at line 16 line ,can any one explain where i did mistake.

trigger addoppamount  on opportunity(after update,after insert) {
   set<id> s=new set<id>();
       for (opportunity op:trigger.new){
     s.add(op.accountid);
    }
    
   map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);

    for(opportunity opp:trigger.new){
    Account acc = new Account();
    acc.id=ma.get(opp.accountid).id;
    list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities)  from account where id =: acc.id];
    system.debug('hiiiiiii'+af);
        for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
        {
        acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error 
            system.debug('hiiiiiii'+acc.total_opportunity_amount__c);

        }
        update acc;
    } 
  • December 02, 2016
  • Like
  • 0
can any one help me in this trigger,I am writting a trigger,which is displaying amount of opportunities of account in account field.I tried in below way,but i am getting this error  execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.addoppamount: line 18, column 1 and also getting another error at line 16 line ,can any one explain where i did mistake
trigger addoppamount  on opportunity(after update,after insert) {
   set<id> s=new set<id>();
       for (opportunity op:trigger.new){
     s.add(op.accountid);
    }
    
   map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);

    for(opportunity opp:trigger.new){
    Account acc = new Account();
    acc.id=ma.get(opp.accountid).id;
    list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities)  from account where id =: acc.id];
    system.debug('hiiiiiii'+af);
        for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
        {
        acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error 
            system.debug('hiiiiiii'+acc.total_opportunity_amount__c);

        }
        update acc;
    }

    
    
      
}
  • December 01, 2016
  • Like
  • 0
Hi,
I have a scenario where on account we have a field called primarychild text box and in contacts of account  we have ischild checkbox field,if ischild is checked for one contact and the ischild should be false for remaining contacts of that account  and checked contact lastname should be displayed on account primarychild text box. 
I have tried but I am not able solve it.

As i am new to coding I can able to analyse but not able to implement .here is my code  where i tried to get record of contacts based on account id and for every account I am checking its contacts and if  ischild is updated to true old records should be false. 

trigger checkonecontact on Contact (before update) {

Set<Id> s=new Set<Id>();

for(contact c:trigger.old){
   s.add(c.accountId);
}


Map<id,contact> cmap=new Map <id,contact>([select name,childeligible__c,account.accountchild__c  from contact where accountId in:s]);

for(account a:[select name,accountchild__c from account where id in:s]){
        Contact obj = cmap.get(c.id);


}


}



 
  • June 27, 2016
  • Like
  • 0
I have wrote a trigger that display error if rating ==hot,for this trigger I wrote testclass but I am getting testclass fail showing following error.
and it is also showing other trigger Trigger.updateAccount,why?can anyone help me 

System.AssertException: Assertion Failed: Expected: The Last Name "hot" is not allowed for DML, Actual: updateAccount: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.updateAccount: line 2, column 1

Trigger:
----------
trigger adderror on Account (before delete) {
 
 for(Account acc:trigger.old)
 {
   if(acc.Rating=='hot')
    {
     acc.addError('Account associtated. Cannot delete this record');

    }
 }


testclass
-------------
@isTest
public class TestAddError{

static testMethod void errorMethod(){
Account acccc=new Account(Rating='hot');
Database.saveResult sr= Database.insert(acccc,false);
System.assertEquals('The Last Name "'+acccc.rating+'" is not allowed for DML',sr.getErrors()[0].getMessage());

}

}
}
  • June 04, 2016
  • Like
  • 0
Hi,
I wrote search functionality,In that i want to display no records found if a user gives value that have no records,this i want to display using javascript.not by pagemessages in controller.Below is the code.Please help me as I am new to java script.

VF:
---------------
<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(val){

var inputValue = document.getElementById(val).value;

<!--var inputValue = document.getElementById('one:two:search').value;-->

if(inputValue.length <= 0){
alert('no records found');
}
else{
actionFunName(inputValue);
}
}
</script>
<apex:pageMessages />

<apex:form id="two">
 <apex:actionFunction name="actionFunName" action="{!searchpositions}"  reRender="two" />

<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold"   />
<apex:inputText value="{!search}"  id="search" onkeyup="js('{!$Component.search}')"   />
<!--<apex:inputText value="{!search}"  id="search" />-->
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="two"/>-->

<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
    <apex:pageBlockSection >
       <apex:pageBlockTable value="{!poslis}" var="pl"   >
         <apex:column value="{!pl.name}"/>
       </apex:pageBlockTable> 
    </apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock rendered="{!blockOnEnter}" > 
    <apex:pageBlockSection id="d">
       <apex:pageBlockTable value="{!pos}" var="p"  >
         <apex:column value="{!p.name}"/>
         <apex:column >
         <apex:inputCheckbox value="{!p.name}"/>
         </apex:column>
       </apex:pageBlockTable>
    </apex:pageBlockSection>
 </apex:pageBlock> 
</apex:form>
</apex:page>

controller:
-------------
public with sharing class searchwithactionstatuscontroller {

    public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}


    public PageReference searchpositions() {
        string holdString ='SELECT name from Position__c  where name like  \'%'+search+'%\' ORDER BY name asc';
        pos=Database.query(holdString);
        
         blockOnLoad=false;
        blockOnEnter=true; 
        return null;
    }


    public String search { get; set; }

public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}

public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}

}

Thanks,
Mahanandeesh.
 
  • May 26, 2016
  • Like
  • 0
Hi All,

Below is the trigger where when contacts are created, there is field called Count_of_Contacts__c  in account which counts no of contacts and display in account field Count_of_Contacts__c.In this I have a doubt regarding map,Please explain me.  

mapcon.put(c.accountid,listcon.size());//In this line we are putting accountids which are in contact object,to get the size of contacts
mapcon.get(ac.id)​       //in this line we are using account reference and getting id for size,but we have to call like this                      know mapcon.get(c.accountid) to get the size,because we have created map which taking accountids of contact,but how it is taking ac.id which is in account for getting size.



trigger contactcountaccount on Contact (after insert) {
list<Id> listContact = new list<Id>();
list<contact> listcon=new list<contact>();
list<account> listAcc= new list<account>(); 

set<Id> s=new set<Id>();
for(contact c:trigger.new){
s.add(c.accountid);
}

list<account> accountId = [select id,name,Count_of_Contacts__c from account where id in:s];
list<contact> contactId=  [select id,accountid,name from contact where accountid in:s];
map<id,Integer> mapcon=new map<id,Integer>();


for(account A:accountId)
{
for(contact C: contactId){
if(c.accountid==a.id){
listcon.add(c);
system.debug('this are list of contacts if ids are equal'+listcon);
mapcon.put(c.accountid,listcon.size());           //please explain
system.debug('this are map of con accountid and consize '+mapcon);


 }
}
}
if(listcon.size()>0){
for(account ac:accountId){
if(mapcon.get(ac.id)==null){                    //please explain
system.debug('GET account id into map'+mapcon.get(ac.id));

ac.Count_of_Contacts__c =0;
}
else{
ac.Count_of_Contacts__c = mapcon.get(ac.id);
system.debug('getting how many contacts with id'+ac.Count_of_Contacts__c);

}
listAcc.add(ac);
system.debug('final list listAcc'+listAcc);

}

}

if(listAcc.size()>0)
update listAcc

Thanks,
B.Mahanandeesh
  • May 23, 2016
  • Like
  • 0
I wrote a class when record is inserted it is redirected to another page and should display that record as output field.I wrote a test class for first class,but i dont know how to write test class for pagereference and 2nd class.Please help me

class 1(save record)
-----------
public with sharing class saveInputController {
public string positionname{set;get;}
   
   
    public PageReference saveposition() {
    position__c p=new position__c();
     p.name=positionname;
     insert p;
     PageReference posPage = new PageReference('https://c.ap2.visual.force.com/apex/showinput?id=' + p.name);//I didnt covered this in test class .
     posPage.setRedirect(true);
     return posPage;
    }
}
testclass for class one
------------------------------------

@isTest
public class testsaveInputController{

public static testmethod void v1 (){
position__c p= new Position__c(name='maha');
insert p;
position__c p1= new Position__c(name='maha1');
insert p1;
position__c p2= new Position__c(name='maha2');
insert p2;
Test.startTest();
saveInputController sic=new saveInputController ();
PageReference myVfPage =sic.saveposition();
Test.stopTest();
System.assertEquals('maha', myVfPage );
}
}



class2(display as outfield)(I am not knowing how to write testclass for this because of page reference)
--------------------------------------
public with sharing class showinputcontroller {
public List<position__c> p{get;set;}

public showinputcontroller(){
p=[select name from position__c where name like :ApexPages.currentPage().getParameters().get('id') limit 5];
}

}

Thanks,
Mahanandeesh.
  • May 18, 2016
  • Like
  • 1