Trigger on document Object. Whenever I update document its populating corresponding platform name on document level.
trigger s360_DocumentSOSLTrigger on Document__c (before insert,before update) {
if((trigger.isInsert || trigger.isUpdate) && trigger.isBefore){
S360_DocumentDetails.documentupdate(trigger.new);
}}
public class S360_DocumentDetails {
public static void documentupdate(List<Document__c> docList){
set<id> Platformset=new set<id>();
for(Document__c doc:docList){
if(doc.Platform__c!=null){
Platformset.add(doc.Platform__c);
}
}
map<id,Platform__c> paltformmap=new map<id,Platform__c>();
for(Platform__c plat:[select id,Aircraft_Manufacturer__c,name from Platform__c where Id in:Platformset]){
paltformmap.put(plat.id,plat);
}
for(Document__c D2:docList){
if(paltformmap.get(D2.Platform__c).name!=null &&
plaformmap.containskey(D2.Platform__c)){
D2.PlatformSOSL__c=paltformmap.get(D2.Platform__c).name;
}else
{
D2.PlatformSOSL__c='';
}
}
}}
Issue facing:
I have executed following code in Anonymous window. before that what I did I just updated "platform" in document level. For perticular that platform I got the error:
Script I have executed in Anonymous window:
List<Document__c> docList=[select
Id,Platform__c,Platform__r.name,Revision__c,Send_Revision_Email__c from
Document__c];
List<Document__c> doclist1=new List<Document__c>();
for(Document__c doc:docList){
doc.Send_Revision_Email__c=true;
doclist1.add(doc);
}
update doclist1;
Error Image:
D2.Platform__c
AND/ORpaltformmap.containsKey(D2.Platform__c)
– Raul May 4 '18 at 9:38D2.Platform__c != null
– Tushar Sharma May 4 '18 at 10:27add check of D2.Platform__c != null
– Tushar Sharma May 4 '18 at 10:33