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
Santosh Shah 4Santosh Shah 4 

How To get AccountId from Quote in Before insert trigger

As per requirement while creating new Quote i have to update Quote field based on Account which Quote is holdinig..So i wrote trigger iin Before Insert.But Due to SF limitatin It will return AccountId always Null.How i can Map Quote with Account if there are multiple Quote with different account  in trigger.new.Belowo is code
for(quote qrec :newRec){
 if(string.isNotBlank(qrec.OpportunityId)){ 
    oppsId.add(qrec.OpportunityId);
	}
}
List<Opportunity> oppsRec = [Select Id,AccountId FROM Opportunity WHERE ID = :oppsId];
 for(Opportunity oppRec : oppsRec){
  if(string.isNotBlank(oppRec.AccountId)){ 
    accId.add(oppRec.AccountId); 
	} 
} 
List<Account> accData = [SELECT Id,name,Partner_Rec__C FROM Account WHERE ID = :accId]; 
List<Partner> partnerRec =[SELECT AccountToId From Partner where AccountFromId = :accId];    
//Perform only if Account doesnt have any partner Rec
  if(PartnerRec.size() == 0){ 
    for(account acc : accData){
     for(Quote qrec :newRec){
      if(string.isBlank(acc.Partner_Rec__C) &&  string.isBlank(acc.ParentId) && ownerManagerMap.containskey(qrec.ownerid)){
        qrec.Manager__c = ownerManagerMap.get(qrec.ownerID);
       }
//How To know here which Quote Associated with which Account ?????Something like below
// if(acc.Id == qrec.accountId)  ---> Update Manger filed on Quote based on Account Availabe on Quote
      else if(string.isNotBlank(acc.Partner_Rec__C) && string.isNotBlank(acc.ParentId)){             
	  qrec.Manager__c = acc.OwnerId; 
}