• Santosh Shah 4
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
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; 
}






 
I'm, just getting 63% code coverage..not able to incerase c..can any one help me
User-added image
Test class:
@isTest
public class TestOpportunityContactRoleHandler {
    @isTest static void TestBeforeInsertMethod(){
        
        Contact ConRec= new Contact();
        ConRec.FirstName = 'Test';
        ConRec.LastName   = 'Test';
        insert ConRec;
        
        Opportunity opps = new opportunity();
        opps.Name='test';
        opps.StageName='Processing';
        insert opps;
        
        OpportunityContactRole oppRole = new OpportunityContactRole();
        oppRole.Role='ROLE1';
        oppRole.ContactId = ConRec.Id;
        oppRole.OpportunityId = opps.Id;
        insert oppRole;
    }

 
Can anyone help me to write test class for following 

apex class: 

public class Emailtemplatehandler {
   
    public static void Sendmailtocustomer(Account acc){
       
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        Messaging.SingleEmailMessage mail        = new Messaging.SingleEmailMessage();
       
        North_acc__c CityRec    = [select Email__c from North_acc__c where name_city =:acc.name_city];
        EmailTemplate et                         = [Select Id, Name from EmailTemplate where Name = 'VFMAIL'];
        list<string> sendTo                      = new list<string>();
       
       
        sendTo.add(CityRec.Email__c);
        mail.setToAddresses(sendTo);
        mail.setSenderDisplayName('Displyname');
        mail.setTargetObjectId(UserInfo.getUserId());
        mail.setWhatId(acc.Id);
        mail.setSaveAsActivity(false);
        mail.setTemplateId(et.Id);
        mails.add(mail);
        system.Messaging.sendEmail(mails);
    }
}
I have parent to child query result stored in map now i want to display value from both obj  in VF email template using apex component but getting error

APEX CLASS LOGIC :

    public Map<Id, List<SObject>> getLocation()
    {
        Map<Id, List<SObject>> locationadd;
        for (account acc :[select id,Phone,(select City__c,State_Province__c,ZipCode__c FROM Addresses__r) from account where id ='xxxxxxxxxxxx'])
         {
          locationadd.put(p.Id, Addresses__r);
        }
         return locationadd;
   }     


APEX COMPONET:
 <apex:repeat value="{!Location}" var="acc4">   
   
   <TR>
      <TD>City</TD>
      <TD>{!Location[acc4].City__c}</TD>
   </TR>
      <TR>
      <TD>City</TD>
      <TD>{!Location[acc4].Phone}</TD>
   </TR>

 </apex:repeat> 
I'm, just getting 63% code coverage..not able to incerase c..can any one help me
User-added image
Test class:
@isTest
public class TestOpportunityContactRoleHandler {
    @isTest static void TestBeforeInsertMethod(){
        
        Contact ConRec= new Contact();
        ConRec.FirstName = 'Test';
        ConRec.LastName   = 'Test';
        insert ConRec;
        
        Opportunity opps = new opportunity();
        opps.Name='test';
        opps.StageName='Processing';
        insert opps;
        
        OpportunityContactRole oppRole = new OpportunityContactRole();
        oppRole.Role='ROLE1';
        oppRole.ContactId = ConRec.Id;
        oppRole.OpportunityId = opps.Id;
        insert oppRole;
    }