Skip to main content
 am retreiving  opportunity records  under a contact (Contact Related list opportunities)  and displaying in a page table......i  am retreving all data  and every thing is good.  But i want add a filter condition where  sample Hype = true. then  all opportunity records under contact where sample hypo field is true should need to retrive.  But  after applying  condition i am getting  Referring a Null object exception for Olist.add(Op)  in below code.  I rendered the Olist in VF page pageblock table. I am not getting error in the code/VF.. after  rendered this to a button. After click buttoon it need to pull records and display here i am getting error.

public with sharing class OppRelatedData {

public Id sid{get;set;}

public string sname{get;set;}    

public list<Opportunity> OppRecords {get; set;}

public list<Opportunity> Olist = new list<Opportunity>();

 

contact cn = new contact();

string contactId = ApexPages.currentPage().getParameters().get('rec');

public OppRelatedData(ApexPages.StandardController controller) {

try{

if(ApexPages.currentPage().getParameters().get('rec')!=null){

 OppRecords = [select id,name,Amount,Sample_Hypo__c,Client_Meeting_Date__c,CloseDate,CreatedDate,Last_Activity_Date__c,LastModifiedDate,StageName,Product_Interest__c,Product_Riders__c from Opportunity WHERE Contact_Name__r.id =:ContactId  AND (not StageName LIKE '%close%') ORDER BY CloseDate ASC ];

System.debug('Opprecords'+OppRecords );

 for(Opportunity op:OppRecords){

 if(op.Sample_Hypo__c == true){

 

 Olist.add(op);

 System.debug('Olist'+Olist);

 

 }

 }

 update Olist;

}

else

System.Debug('There is no contact associated with Opportunity');

}

catch(DmlException e){

System.Debug(e.GetMessage());

}

}

}
3 respuestas
  1. 15 ene 2015, 15:23
    Hi Anvesh, 

    It will show you opportunites related to contact as you have mentioned Contact_Name__r.id =:ContactId in your query. 

    and second thing -you are doing DML , which is  not required. 

    update Olist;// not required

    Sameer
0/9000