function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TilluTillu 

How to retrive records which are not in list?

I have Contact as master and  policy as detailed. i want retrive records other than this list..

 

List<contact> cp = [select id,Customer_Producer__c from contact];  //this is contact List

 

List<Policy__c> pList1 = [select id,IssueDate__c from Policy__c where Contact_1__c IN: cList]; // Records of policy under contact


List<Policy__c> pList2 = [select id,IssueDate__c from Policy__c where Contact_1__c IN: cList And NotIn pList1]; // I want to retrive otherthan records of pList1. I have written for just to understand.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
gbu.varungbu.varun

You can create a new List as

List<Policy__c> pList3 = [select id,IssueDate__c from Policy__c where ID <>:pList1 ];

All Answers

gbu.varungbu.varun

You can create a new List as

List<Policy__c> pList3 = [select id,IssueDate__c from Policy__c where ID <>:pList1 ];

This was selected as the best answer
Ashish_SFDCAshish_SFDC

Hi Anvesh,

 

See the links might help,

 

Comparing Values between two lists
http://salesforce.stackexchange.com/questions/9910/comparing-values-between-two-lists

 

Checking to see if a value is present in a list - Apex
http://salesforce.stackexchange.com/questions/4218/checking-to-see-if-a-value-is-present-in-a-list-apex

 

Regards,
Ashish