• shakila G
  • NEWBIE
  • 204 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 58
    Questions
  • 57
    Replies
Hi All,

In lightnin page am using two submit button. 
1.Save
2.Save and New
When user click on save  based on handle on success am navigating new record detial page.
when user clicks save and new am unable to navigate to new screen that also going to same record details page.

How to handle two method seprately on success?

Thanks in Advance
Argument cannot be null in Apex class
Hi All,

When the Belowmethod called through VF page button , SOme time am getting below error

Argument cannot be null.

Error is in expression '{!addworkorders}' in component <apex:commandButton> in page check_available_rawmaterials: Class.Check_Available_Rawmaterials.addworkorders: line 49, column 1
Which is Highlightes as Bold in the below mentioned code

Kindly please help me to over come from this issue
 public void addworkorders() {
        AttachmentCallWrapperlist3.clear();
        setprodid.clear();
        setRMid.clear();
        lstrmri.clear();
        lstComp .clear();
        //wraplist.clear();
        //Result.clear();
        //Result1.clear();
        //Result2.clear();
        iRmInvLst.clear();
        AttachmentCallWrapperlist.clear();
        AttachmentCallWrapperlist3.clear();
         Productnamemap.clear();
        Productqtymap.clear();
            
        show = true;
        /*for (Project__c iRow:lstworkorder) {if (iRow.Selected__c == true) {   setRMid.add(iRow.Opportunity__c);
            } 
        }   */                     
        Boolean isTrue = TRUE;
        IF(setprojectid!=Null){
            lstrmri =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:setprojectid]; 
            IF(lstrmri .size()>1){
            For(OpportunityLineItem  olt:lstrmri ){ 
            setprodid.add(olt.Product2Id);
                }
            }                          
        }  
        If(lstrmri.size()>0) { wraplist=new List<AddWrapperField1>();  
            Result=[select SUM(Quantity) Totalqty,Product2.name ProdName from OpportunityLineItem where opportunityID=:setprojectid      group By Product2.name];                          
            
            IF(Result.size()>0){
            for(AggregateResult res:Result){   wraplist.add(new AddWrapperField1(Res)); 
                Productqtymap.put((String)res.get('ProdName'), (Decimal)res.get('Totalqty'));
            }   
            }
        }  
        IF(setprodid!=Null){
            lstComp =[select ID,name,Raw_Material__c,Selected__c,Product__R.name,Total_Measurement__c  from Component__c where Product__r.name in : Productqtymap.keyset()];
            If(lstComp .size()>0) {
                wraplist1=new List<AddWrapperField>();         
                Result1=[select SUM(Total_Measurement__c) TotalMeasure,Raw_Material__r.name Name,Product__r.name pName  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Product__r.name,Raw_Material__r.name]; 
                Result2=[select Raw_Material__r.name Name  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Raw_Material__r.name]; 
                     IF( Result1.SIZE()>0 && Productqtymap!=Null){
                          for(AggregateResult res2:Result1){  
                 Rawmaterialmap.put((string)res2.get('Name'),(Double)res2.get('TotalMeasure')* Productqtymap.Get((String)res2.get('pName')));
                 }
            }  
            If(Result1.size()>0 && Productqtymap!=NUll && Rawmaterialmap!=Null ){
                for(AggregateResult res1:Result1){ 
                    AttachmentCallWrapper I= New AttachmentCallWrapper();  
                    i.qty=0; 
                    i.RequiredMaterial =(string)res1.get('Name'); 
                       If(Rawmaterialmap.size()>0){
                       i.Qty=Rawmaterialmap.get((string)res1.get('Name')); }
                    i.ProductName =(string)res1.get('pName');             
                    i.ProdutQty  = Productqtymap.Get((String)res1.get('pName')); 
                    AttachmentCallWrapperlist.add(i);            
                } 
                
                }
                
                if(AttachmentCallWrapperlist.size()>0 && Productqtymap!=Null){
                For(AttachmentCallWrapper  atc: AttachmentCallWrapperlist){           
                    if (Productqtymap.containskey(atc.RequiredMaterial)){            
                        Productqtymap.put(atc.RequiredMaterial,
                        (atc.Qty+ Productqtymap.get(atc.RequiredMaterial)) );     
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);         
                    }Else{
                        Productqtymap.put(atc.RequiredMaterial, atc.Qty);
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);    
                    }
                }
            }
        }  
        
        }
        iRmInvLst=[SELECT id,Name,RawMaterial__c,Available_RM_in_OrigMeasure__c ,Unit__c FROM Raw_Material_Inventory__c 
                   WHERE Name IN :Productnamemap.keyset()];
        IF(iRmInvLst.Size()>0 && Productqtymap!=Null){
            For(Raw_Material_Inventory__c INV: iRmInvLst){
                AttachmentCallWrapper2 atc4 = new AttachmentCallWrapper2();
                atc4.RequiredMaterial=INV.NAME;  
                atc4.Stock=INV.Available_RM_in_OrigMeasure__c;
                if(INV.Available_RM_in_OrigMeasure__c<Productqtymap.get(INV.NAME)){
                atc4.Requiredqty=Productqtymap.get(INV.NAME)-INV.Available_RM_in_OrigMeasure__c;
                    atc4.PurchaseUnit=INV.Unit__C;
                }
                atc4.Qty=Productqtymap.get(INV.NAME);   AttachmentCallWrapperlist3.add(atc4);
                
            }
        }
    }

Thanks,
Shakila
Hi All,

When the Belowmethod called through VF page button , SOme time am getting below error
Argument cannot be null.

Error is in expression '{!addworkorders}' in component <apex:commandButton> in page check_available_rawmaterials: Class.Check_Available_Rawmaterials.addworkorders: line 40, column 1

Kindly please help me to over come from this issue

 public void addworkorders() {
        AttachmentCallWrapperlist3.clear();
        setprodid.clear();
        setRMid.clear();
        lstrmri.clear();
        lstComp .clear();        
        iRmInvLst.clear();
        AttachmentCallWrapperlist.clear();
        AttachmentCallWrapperlist3.clear();
         Productnamemap.clear();
        Productqtymap.clear();
            
        show = true;                         
        Boolean isTrue = TRUE;
        IF(setprojectid!=Null){
            lstrmri =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:setprojectid]; 
            IF(lstrmri .size()>1){
                For(OpportunityLineItem  olt:lstrmri ){  setprodid.add(olt.Product2Id);
                }
            }                          
        }  
        If(lstrmri.size()>0) { wraplist=new List<AddWrapperField1>();  
            Result=[select SUM(Quantity) Totalqty,Product2.name ProdName from OpportunityLineItem where opportunityID=:setprojectid      group By Product2.name];                          
            for(AggregateResult res:Result){   wraplist.add(new AddWrapperField1(Res)); 
                Productqtymap.put((String)res.get('ProdName'), (Decimal)res.get('Totalqty'));
            }   
        }  
        IF(setprodid!=Null){
            lstComp =[select ID,name,Raw_Material__c,Selected__c,Product__R.name,Total_Measurement__c  from Component__c where Product__r.name in : Productqtymap.keyset()];
            If(lstComp .size()>0) {
                wraplist1=new List<AddWrapperField>();         
                Result1=[select SUM(Total_Measurement__c) TotalMeasure,Raw_Material__r.name Name,Product__r.name pName  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Product__r.name,Raw_Material__r.name]; 
                Result2=[select Raw_Material__r.name Name  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Raw_Material__r.name]; 
                for(AggregateResult res1:Result1){ 
                    AttachmentCallWrapper I= New AttachmentCallWrapper();       
                    i.qty=0;
                    if(Productqtymap!=null){
                       Rawmaterialmap.put((string)res1.get('Name'),(Double)res1.get('TotalMeasure')* Productqtymap.Get((String)res1.get('pName')));
                       }
                    i.RequiredMaterial =(string)res1.get('Name');         
                    i.Qty=Rawmaterialmap.get((string)res1.get('Name')); 
                    i.ProductName =(string)res1.get('pName');                 
                    i.ProdutQty  = Productqtymap.Get((String)res1.get('pName'));    
                    AttachmentCallWrapperlist.add(i);            
                } 
                For(AttachmentCallWrapper  atc: AttachmentCallWrapperlist){           
                    if (Productqtymap.containskey(atc.RequiredMaterial)){            
                        Productqtymap.put(atc.RequiredMaterial, (atc.Qty+ Productqtymap.get(atc.RequiredMaterial)) );     
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);         
                    }Else{
                        Productqtymap.put(atc.RequiredMaterial, atc.Qty);
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);    
                    }
                }
            }
        }  
        iRmInvLst=[SELECT id,Name,RawMaterial__c,Available_RM_in_OrigMeasure__c ,Unit__c FROM Raw_Material_Inventory__c 
                   WHERE Name IN :Productnamemap.keyset()];
        IF(iRmInvLst.Size()>0){
            For(Raw_Material_Inventory__c INV: iRmInvLst){
                AttachmentCallWrapper2 atc4 = new AttachmentCallWrapper2(); 
                atc4.RequiredMaterial=INV.NAME;   
                atc4.Stock=INV.Available_RM_in_OrigMeasure__c;
                if(INV.Available_RM_in_OrigMeasure__c<Productqtymap.get(INV.NAME))
                { 
                atc4.Requiredqty=Productqtymap.get(INV.NAME)-INV.Available_RM_in_OrigMeasure__c;
                    atc4.PurchaseUnit=INV.Unit__C;
                }
                atc4.Qty=Productqtymap.get(INV.NAME);
                AttachmentCallWrapperlist3.add(atc4);
                
            }
        }
    } 

Thanks,
Shakila
 
Hi All,

Am trying to group the table values in lightning component.Please help me on this to resolve this issue.

How to aggregate the bewlo field values. After aggragte I need to display a single row for each group in Lightning component.
any one can help on this?

User-added image

Thanks,
Shakila

Hello All,

If the custom object record getting created  in salesforce i want to send that data to third party application as JSON Response.

If any having sample code please share to review the steps

Thanks,
Shakila

 

HI,

Am looking for Salesforce PD1 SP19 dumps.
If anyone have.please let me know
HI All,

Am trying to simplify the sales force Mobile Users objects layout.
If the user logged in the browser it should be actual page layout. If the same user logged in Mobile App should be a Simplified layout.
How to display a different page layout for Mobile and browser based.

Kindly assist me how to accomplish this.


Thanks,
Shakila
 
Hi All,

I want to send  a record third party Application..whenever the records getting created in salesforce.

KIndly provide me some solution how to send it .
HI All,

Am trying to fetch Custom object related Approval process records information from processinstance step using soql workbecn.
Select Account__r.Name,Team_Member__r.Name ,Team_Member__r.ISActive,Team_Member_Email__c,Team_Role__c, Status__c,RHMS_Approval_Status__c, Approval_Status__c ,(SELECT ProcessInstance.TargetObjectId ,Comments FROM ProcessInstanceStep)from Account_Team__C
where ID='a4Qc0000000kBDt'

Am getting following error..

Didn't understand relationship 'ProcessInstanceStep' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Kindly let me know ..How to fetch alll those records using workbench..
Hi All,

I wrote  a wrapper classs to store the different object value in one list.

Now my wrapper class contain the list  like below :
Material Name   Qty
Rim                       2
Rope                     2
Wood                  5.666
Rim                         7
Wood                       2
Rim                      0.5555

i want to consolidate this value as like below



Material Name    Qty
Rim                       9.5555
Rope                     2
Wood                   7.666

kindly some one guide me to accomplish this.
Hi All,

I created a new field in user with the data type number am trying to update the field called Total License from user license object .

to acomplish this i wrote a bacth class.But its not updating this field.

Kindly let mw know ,Where i do changes
Batch Class:
global class totallicensecount implements Database.Batchable<SObject>{
Map<ID,String> License= New Map<ID,String>();
Map<string,Integer> License1= New Map<string,Integer>();
list<user> query1=new list<user>();
set<string> setuserlicense=new set<string>();
list<user> listofuser=new list<user>();

        
        global Database.QueryLocator start(Database.BatchableContext bc){
                string query='select Id,name,TotalLicenses from Userlicense'; 
                query+='limit 1';       
                return Database.getQueryLocator(query);
        
        }
        

        global void execute(Database.BatchableContext bc,list<Userlicense> scope){
        
                for(Userlicense us:scope){
                License1.put(Us.Name,us.TotalLicenses);
                setuserlicense.add(us.name);
                }
            
                    query1=[select Id,name,profile.Userlicense.name,Profile.UserLicense.TotalLicenses,Type__C,Total_license_count__c from user where profile.Userlicense.name in :setuserlicense];
                    for(user us1:query1){
                    us1.Total_license_count__c=License1.get(us1.profile.Userlicense.name);
                    listofuser.add(us1);                   
                   
                }
            
        IF(listofuser.size()>0){
        
        update listofuser;
        
        }
}



global void finish (Database.BatchableContext bc){
}



}


 
Hi All,
I have written the apex class to insert a record in Salesforce before inserting record itself it's getting redirect from the page.
Kindly let me know how to overcome from the issue

My VF Page:
<apex:page Controller="Rawmaterial_Cost_Accounting"  tabStyle="Vendor__c" sidebar="false">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"></link>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
//purchd RM
var prdrmtags = [];
<apex:repeat value="{!rmTagLst}" var="rm">
    prdrmtags.push('{!rm}');
</apex:repeat>
<apex:repeat value="{!rmTagLst2}" var="rm2">
    prdrmtags.push('{!rm2}');
</apex:repeat>



//vendor 
var vendortags = []; 
<apex:repeat value="{!vendorTagLst}" var="vendor">
    vendortags.push('{!vendor}');
</apex:repeat>
<apex:repeat value="{!vendorTagLst2}" var="vendor2">
    vendortags.push('{!vendor2}');
</apex:repeat>

//received by(employee)
var recvBytags = [];
<apex:repeat value="{!receivedByTagLst}" var="recvBy">
    recvBytags.push('{!recvBy}');
</apex:repeat>
<apex:repeat value="{!receivedByTagLst2}" var="recvBy2">
    recvBytags.push('{!recvBy2}');
</apex:repeat>

$( function() {
    $( ".prdrmtags" ).autocomplete({
        source: prdrmtags
    });
     $( ".vendortags" ).autocomplete({
        source: vendortags
    });
         $( ".recvBytags" ).autocomplete({
        source: recvBytags
    });
    
 $(".prdrmtags").on( "autocompletechange", function(event,ui) {
   // post value to console for validation
     setRmUnit();
     //  alert('changed');
 });
} );
</script>
   <apex:form >
        <apex:pageBlock title="Purchasd Raw Material Informations" rendered="{!show1}" >
         <apex:pageblockButtons location="Bottom" >
        <apex:inputtext value="{!addCount}" />
           <apex:commandButton value="Add Row" action="{!addPrdRM}"  rendered="{!show1}" ID="theButton"/>
          </apex:pageblockButtons>  
        
    <apex:pageBlockTable value="{!iPrdRmLst}" var="iPrdRm" id="iPrdRmTb">
        <apex:column >
            <apex:facet name="header">Raw Material</apex:facet>
            <apex:inputField value="{!iPrdRm.Raw_Material__c}" style="width: 250px;" styleClass="prdrmtags" required="true">
               
            </apex:inputField>
        </apex:column> 
        
        <apex:column >
            <apex:facet name="header">Vendor Name</apex:facet>
            <apex:inputField value="{!iPrdRm.Vendor__c}" style="width: 250px;" styleClass="vendortags" required="true">
               
            </apex:inputField>
        </apex:column> 
        
        <apex:column >
            <apex:facet name="header">Price</apex:facet>
            <apex:inputField value="{!iPrdRm.Price_Unit__c}" style="width: 250px;" required="true">
               
            </apex:inputField>
        </apex:column> 
        
        
       <!--- <apex:column >
            <apex:facet name="header">Purchase Unit</apex:facet>
            <apex:outputField value="{!iPrdRm.Unit__c}" style="width: 250px;"/>
        </apex:column>  -->
       
         
       
    </apex:pageBlockTable>
    
    <apex:pageblockButtons location="Bottom" >
                  <apex:commandButton value="Save" action="{!saveEntity}" />
          </apex:pageblockButtons>            
     
              
            
   </apex:pageBlock> 
   </apex:form>
</apex:page>

Apex class:
public class Rawmaterial_Cost_Accounting{
    //list 1
    List<String> rmTagLst=new List<String>();
    List<String> vendorTagLst=new List<String>();
    List<String>  receivedByTagLst=new List<String>();     
     public static String  purchdOrderNm{get; set;}     
     boolean show = true;  boolean show1 = true; boolean Iflag= False;
    //list 2
    List<String> rmTagLst2=new List<String>();
    List<String> vendorTagLst2=new List<String>();    
    List<String>  receivedByTagLst2=new List<String>();
    
    Map<String,Id> iRmNmToRmId=new Map<String,Id>();
    Map<String,String> iRmNmToRmUnit=new Map<String,String>();
    Map<String,Id> iRmIdToRmInvId=new Map<String,Id>();
     Map<String,Id> Ipolist=new Map<String,Id>();
    Map<String,Id> iVndrNmToVndrId=new Map<String,Id>();
    Map<String,Id> iRecvByNmToEmpId=new Map<String,Id>();
    Public List<RawMaterial_Supplied__c > iPrdRmLst =New  List<RawMaterial_Supplied__c >();
      List<RawMaterial_Supplied__c > iPrdRmLst1=new List<RawMaterial_Supplied__c >();
     public static Integer addCount {get; set;}
     
    RawMaterial_Supplied__c  iPrdRm=new RawMaterial_Supplied__c ();
    Object_Helper__c iObj=new Object_Helper__c();
    
    public Object_Helper__c getIObj(){
        return iObj;
    }
    public void setIObj(Object_Helper__c iObj){
        this.iObj=iObj;
    }
    public List<RawMaterial_Supplied__c > getIPrdRmLst(){
        return iPrdRmLst;
    }
    public void setIPrdRmLst(List<RawMaterial_Supplied__c > iPrdRmLst){
        this.iPrdRmLst=iPrdRmLst;
    }
    public RawMaterial_Supplied__c  getIPrdRm(){
        return iPrdRm;
    }
    public void setIPrdRm(RawMaterial_Supplied__c  iPrdRm){
        this.iPrdRm=iPrdRm;
    }
    
    //list 1
    public List<String> getRmTagLst(){
        return rmTagLst;
    }
    public void setRmTagLst(List<String> rmTagLst){
        this.rmTagLst=rmTagLst;
    }    
    public boolean getshow1()
    {
         return show1;
    }    
        
    public List<String> getVendorTagLst(){
        return vendorTagLst;
    }
    public void setVendorTagLst(List<String> vendorTagLst){
        this.vendorTagLst=vendorTagLst;
    }
    
     
    
    public List<String> getReceivedByTagLst(){
        return receivedByTagLst;
    }
    public void setReceivedByTagLst(List<String> receivedByTagLst){
        this.receivedByTagLst=receivedByTagLst;
    }
    
  
    
    
    //list 2
    public List<String> getRmTagLst2(){
        return rmTagLst2;
    }
    public void setRmTagLst2(List<String> rmTagLst2){
        this.rmTagLst2=rmTagLst2;
    }    
    
    
    public List<String> getVendorTagLst2(){
        return vendorTagLst2;
    }
    public void setVendorTagLst2(List<String> vendorTagLst2){
        this.vendorTagLst2=vendorTagLst2;
    }
    
    
    public List<String> getReceivedByTagLst2(){
        return receivedByTagLst2;
    }
    public void setReceivedByTagLst2(List<String> receivedByTagLst2){
        this.receivedByTagLst2=receivedByTagLst2;
    }
    
   
    
    Integer counter=0;    
    
    public  Rawmaterial_Cost_Accounting(){
        
        
        //rw material autocomplete  
        List<RawMaterial__c> iRmLst=[SELECT id, Name,selected__C FROM RawMaterial__c];
        
        for(RawMaterial__c iRM :iRmLst){
            
            iRmNmToRMId.put(iRM.Name.trim(), iRM.Id);
          
            
            //to diplay in javascript tag
            if(iRM.Name.contains('\'')){
                iRM.Name= iRM.Name.replace('\'', '\\\'');
                
            }
            ++counter;
            if(counter<1000){  
                rmTagLst.add(iRM.Name);
            }else{
                rmTagLst2.add(iRM.Name); 
            }
        }        
        //re initialize counter
        counter=0;        
        //vendor autocomplete
        List<Vendor__c> iVendorLst=[SELECT id, Name FROM Vendor__c];
        
        for(Vendor__c iVendor :iVendorLst){
            
            iVndrNmToVndrId.put(iVendor.Name, iVendor.Id);
            
            //to diplay in javascript tag
            if(iVendor.Name.contains('\'')){
                iVendor.Name= iVendor.Name.replace('\'', '\\\'');
                
            }
            ++counter;
            if(counter<1000){  
                vendorTagLst.add(iVendor.Name);
            }else{
                vendorTagLst2.add(iVendor.Name);
            }
        }      
        
         
          
        //re initialize counter
        counter=0;
        
        //received by autocomplete
        List<Employee__c> iEmployeeLst=[SELECT id, Name FROM Employee__c];
        
        for(Employee__c iEmp :iEmployeeLst){
            
            iRecvByNmToEmpId.put(iEmp.Name, iEmp.Id);
            
            ++counter;
            if(counter<1000){  
                receivedByTagLst.add(iEmp.Name);
            }else{
                receivedByTagLst2.add(iEmp.Name); 
            }
        }                
        system.debug('iRmNmToRMId'+iRmNmToRMId);
    }
    
    
    
    public PageReference addPrdRM(){  
    If(addCount!=Null){    
       for (Integer idx=0; idx<addCount; idx++) { 
        RawMaterial_Supplied__c  iPrdRm=new RawMaterial_Supplied__c ();
         iPrdRmLst.add(iPrdRm);        
    }
    
    }
       if(iPrdRmLst.size()<=0){            
            show1 = True;           
        }   
    return null;
    }
    
    public PageReference saveEntity(){
        try{ 
            List<Id> iRmIdLst=new List<String>();
            
            for(RawMaterial_Supplied__c   iPrdRm:iPrdRmLst){
                iPrdRm.Period_From__c=system.Today();
                iPrdRm.Price_Unit__c= iPrdRm.Price_Unit__c;
                iPrdRm.Vendor__c=iVndrNmToVndrId.get(iPrdRm.Vendor__c); 
                iPrdRm.Raw_Material__c=iRmNmToRMId.get(iPrdRm.Raw_Material__C);
                iPrdRmLst1.add(iPrdRm);
            }
            if(iPrdRmLst1.size()>0){
                insert iPrdRmLst1;
                Iflag=True;
                   
            }          
              
            else{
               // sendEmail(iPrdRmLst);
            }            
            if(Iflag==True){
            
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Purchased raw materials succesfully added')); 
                 PageReference exRM = new PageReference('/apex/V2_Raw_Material_Received');               
                exRM.setRedirect(true);
                return exRM;  
                
               
                                                
            }else{
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Purchased raw materials succesfully added')); 
            }   
            
        }catch(Exception e){
            system.debug('Exception Line' +e.getLineNumber());  
            system.debug('Exception Cause' +e.getCause());  
            system.debug('Exception' +e.getStackTraceString()); 
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Oops: something went wrong. Please contact admin.'));
        }        
        return null;
    }
     
    }1
 
Hi All, 
I have written an send email Functionality to send two different quote template based on the selected Template.

I passed the VF Constructor in Page Button. Sometimes its working fine and  some time it is not working Properly(Email is not triggering from salesforce just inserting the attachment in Salesforce )

Kindly assist me on this.It's very urgent kindly help me on this

MY Apex Class:
public class GenerateQuoteSpec{

    Public string QuoteId;
    public Quote Quot = new Quote();
    public Quote getQuot() { return Quot; }
    public Quote Quotedata= new Quote();
    public Blob content;
    string Contentname;
    string Contentname1;
    public Contact con { get; set; }
    public String subject { get; set; }
    public String emailbody { get; set; }
    public string CC{get;set;}
    List<String> CCAddress = new List<String>();
    
        
    public GenerateQuoteSpec(ApexPages.StandardController controller) {
        QuoteId = ApexPages.currentPage().getParameters().get('id');
        
        Quotedata= [select id,Name,Customer_name__c,QuoteNumber,Email,Letter_Head_New__c, Project_Type__c,ContactId from Quote where id =: QuoteID];         
           
           
      
        subject = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
        emailbody = 'Greetings from Ankidyne!\n\nPlease find the quotation for our products. kindly approve our quotation to serve your organization.\n\nPlease Check the Quote Pdf attached for further information.\n\n';
    }

    public void generatepdf(){
        try {
            Contentname = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
            Contentname1 = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
            pageReference pdfpage;
            if(Quot.Quote_With_Tech_Spec__c == true) {
                system.debug('QuoteId'+QuoteId);
                pdfpage = page.GST_Image_Discount;
            }
             if(Quot.Quote_Without_Tech_Spec__c== true) { 
                system.debug('QuoteId'+QuoteId);
                pdfpage = page.GST_No_Discount;
            }
            pdfpage.getParameters().put('id',QuoteId);
            pdfpage.setRedirect(true);
            content = pdfpage.getcontent();
            Attachment att = new Attachment(ParentId=QuoteId, Body=content, ContentType='.pdf');
            // save this content in attachment
            if(Quot.Quote_With_Tech_Spec__c == true) {
                att.Name = Contentname;
            } if(Quot.Quote_Without_Tech_Spec__c== true) {
                att.Name = Contentname1;
            }
            insert att;
        }
        catch(exception ex) {
            apexpages.Message emsg = new apexpages.Message(apexpages.severity.WARNING,ex.getmessage());
            ApexPages.addMessage(emsg);
        }
    } 
    
    public pagereference save() {
        if((Quot.Quote_With_Tech_Spec__c == false && Quot.Quote_Without_Tech_Spec__c == false) || 
                (Quot.Quote_With_Tech_Spec__c == true && Quot.Quote_Without_Tech_Spec__c == true)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please select one option to continue'));
            return null;
        }
        generatepdf();
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }  
    
    public pagereference saveandsend() {
    
     con =  [select ID,Email,Email_Additional__c,CCEmail__c from Contact where ID=:Quotedata.ContactId] ; 
     
        if((Quot.Quote_With_Tech_Spec__c == false && Quot.Quote_Without_Tech_Spec__c == false) || 
                (Quot.Quote_With_Tech_Spec__c == true && Quot.Quote_Without_Tech_Spec__c == true)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please select one option to continue'));
            return null;
        }
        generatepdf(); 
        string[] Emailaddr = new string[]{};
        String[] ccAddresses = new String[]{};
        IF(CC!=Null || CC!='')
        {
        CCAddress=CC.split(',');
        }
        IF(con.Email!=Null || con.Email!='' || con.Email_Additional__c!=Null || con.Email_Additional__c!=''){
        Emailaddr.add(con.Email);
        Emailaddr.add(con.Email_Additional__c);
       }
        try {
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setFileName(Contentname+'.pdf');
            attach.setBody(content);
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(Emailaddr);
            email.setBccSender(true);
            email.setccAddresses(CCAddress);
            system.debug(emailbody);
            emailbody = emailbody.replace('\n','<br>');
            system.debug(emailbody);
            email.setSubject(Contentname);
            email.setHtmlBody(emailbody);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach}); 
            system.debug('QuoteContactId' + con);
            
            // Send the email
             Messaging.SendEmailResult [] sendResult  = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
            
           } Catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'The Email Address Provided in the contact information is not valid one and the Email address is:'+ex.getmessage()));
        }
        
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }
    
    public pagereference cancel() {
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }         
}




 
Hi All,

We have the plan to implement the QR code scanner.

Concept:  When the material dispatched from the Stores based on the QRCode Scanner Gun should get the scanned material information into Salesforce Visualforce page after that, the store maintenance person should enter the quantity of material into salesforce. once the record saved into salesforce stock should be reduced against each material.

My Question is how to get a scanned material information into salesforce?

Kindly Give me a suggestion this



 
HI All,

Am Trying show list of records from Different object Using Wrapper Class.But its not returning any values .

Kindly Help me on this

VF Page:
<apex:page renderAs="PDF" standardController="Project__c" extensions="Dispatch_Workorder_Checklist" applyBodyTag="False" ShowHeader="False"  applyHtmlTag="False">
    <html>
      <head>
        <style>
            @page {
                
                margin-top: 4cm;
                margin-bottom: 2cm;
                margin-right:1CM;
                 margin-Left:1CM;
                  padding: 5px;
                  
                @top-center {
                    content: element(header);
                }
                @bottom-left {
                    content: element(footer);
                }
            }
    
            div.header {
                width: 100%;
                padding: 5px;
                position: running(header);
            }
            div.footer {
                display: block;
                padding: 5px;
                position: running(footer);
            }
            .pagenumber:before {
                content: counter(page);
            }
            .pagecount:before {
                content: counter(pages);
            }
            div.content {
                 border: 1px solid black;
                 padding: 5px;
                width: 100%;
            }        
        </style>
    </head>
    
   
    
     <!-- ==== Header=== -->
      
              <div class="header" >               
                    <p align="center"><b>WorkOrder Dispatch Check List</b></p>
                 <p align="Left"><b>  Project Name: </b><apex:outputField value="{!CPWR.Name}" /></p>                
                   <p align="Left"><b>  Project Type :</b> <apex:outputField value="{!CPWR.Project_Type__c }" /></p>   
                    <p align="Left"><b>  No of Products: </b><apex:outputField value="{!CPWR.Total_Product_Qty__c}" /></p>  
                 
                 
               </div>
     <!-- ==== Header=== -->
    
    <!-- ==== Product Deatils=== -->
    
        
        <apex:outputText style="page-break-Before: Avoid; white-space:nowrap" > 
       
       
        <div class="Content" style="position:absolute; width:100% white-space:nowrap">
    
        <table style="font-size:13px;font-face:Arial;page-break-inside: avoid;white-space:nowrap " border="1" rules="cols" cellspacing="0" width="100%" cellpadding="0"  >
             
                <tr  height="30" width="100%" style="font-family: sans-serif; white-space:nowrap;font-weight: bold; font-size: 10pt;">
                                <th align="center">Sl.No</th>
                                 <th  align="center" > Product Name</th>
                                <th align="center">Dispatch Material Name</th>
                                <th  align="center">Required Quantity</th>  
                                 <th  align="center">Product Quantity</th> 
                                
                                 
                </tr>  
            
            
                               <apex:variable value="{!0}" var="icount" />
                                <apex:repeat value="{!product}" var="line">                                
                               <apex:variable value="{!icount+ 1}" var="icount" />
                             
               <tr> 
                                <td style="text-align:center; " border-style="solid;"  width="10%"  >{!icount}.</td>  
                                <td width="10%" align="center">{!line.ProductName }" </td>
                                <td width="10%" align="center">{!line.RequiredMaterial }</td> 
                                   <td width="10%" align="center">{!line.QTy }</td> 
                               <td width="10%" align="center">{!line.ProdutQty }</td> 
                                
                                
                  </tr>            
                             
              </apex:repeat>     
                 
                 
                                                                 
                                        
            
         </table>
        </div>
    
    </apex:outputText>    
                    
             
       
    </html>
    </apex:page>

Apex Class:

public class Dispatch_Workorder_Checklist {
public Project__c CPWR {get;set;}
list<OpportunityLineItem> listlinitem = New List<OpportunityLineItem>();
list<Dispatch_Product_Checklist__c> listdisprod = New List<Dispatch_Product_Checklist__c>();
Set<ID> setproducID = New Set<ID> ();
Map<ID,Decimal> ProdQty= New Map<ID,Decimal>();
public list<Intermediate> intermediatelist = New list<Intermediate>();
public list<Intermediate> intermediatelist1 = New list<Intermediate>();
list<Product2> listprod = New list<Product2>();
Map<ID,String> ProdName= New Map<ID,String>();
    
    public list<Dispatch_Product_Checklist__c > getlistdisprod ()
    {
    Return listdisprod ;
    }
    
    public list<OpportunityLineItem > getlistlinitem()
    {
    Return listlinitem ;
    }
    
    
    public list<Intermediate> getproduct()
    {
    Return intermediatelist1;
    }
   

    public Dispatch_Workorder_Checklist(ApexPages.StandardController controller) {
    
                CPWR=[select ID,Name,Opportunity__c,Total_Product_Qty__c,Project_Type__c from Project__c  where ID=:ApexPages.CurrentPage().getParameters().get('Id')];
                listlinitem =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:CPWR.Opportunity__c];
                        For(OpportunityLineItem opp: listlinitem )   {    
                                     
                          setproducID.add(opp.Product2Id );
                          ProdQty.put(opp.Product2Id ,opp.Quantity);
                    }
                           listdisprod =[select ID,Name,Product__c,Quantity__c from Dispatch_Product_Checklist__c where Product__c=:setproducID order by Product__c]; 
               IF(setproducID!=Null){
                       listprod= [select ID, Name from Product2 where ID=:setproducID];               
               }
                   
                        For(Product2 pro: listprod)
                        {
                        ProdName.put(pro.ID,PRo.Name);
                        }
                  
              
              
    }
    
    
    
  
   
 Public Void getPRoductlist(){
 If(listprod.size()>0) {
 For(Dispatch_Product_Checklist__c  DP:listdisprod ) {
 
         Intermediate I= New Intermediate();
         i.RequiredMaterial =dp.Name;
         i.Qty=dp.Quantity__c ;
         i.ProdutQty =ProdQty.get(dp.Product__c);
         i.ProductName =ProdName.get(dp.Product__c);
         intermediatelist.add(i);
         
         }
 
     }
 
 
 }
 
 public void getwrapperlist()
 {
 
 For(Intermediate Im: intermediatelist)
 {
 intermediatelist1.add(IM);
 
 }
   
   }
 
 
 Public Class Intermediate{
 
 public Decimal QTy {Get;set;}
 Public String RequiredMaterial {get;set;}
 Public Decimal ProdutQty {get;set;}
 public String ProductName {get;set;}
 
 
 
}
 
    
    

}
I want to Muliple list field value into  another list field Value after displaying into the VF 
page.

But my Vf repaet page Working Wrong kindly Help m eon this

VF Page

<apex:page renderAs="PDF" standardController="Project__c" extensions="Dispatch_Workorder_Checklist" applyBodyTag="False" ShowHeader="False"  applyHtmlTag="False">
    <html>
      <head>
        <style>
            @page {
                
                margin-top: 4cm;
                margin-bottom: 2cm;
                margin-right:1CM;
                 margin-Left:1CM;
                  padding: 5px;
                  
                @top-center {
                    content: element(header);
                }
                @bottom-left {
                    content: element(footer);
                }
            }
    
            div.header {
                width: 100%;
                padding: 5px;
                position: running(header);
            }
            div.footer {
                display: block;
                padding: 5px;
                position: running(footer);
            }
            .pagenumber:before {
                content: counter(page);
            }
            .pagecount:before {
                content: counter(pages);
            }
            div.content {
                 border: 1px solid black;
                 padding: 5px;
                width: 100%;
            }        
        </style>
    </head>
    
     <!-- ==== Header=== -->
      
              <div class="header" >               
                    <p align="center"><b>Dispatch Check List</b></p>
                 <p align="Left"><b>  Project Name:<apex:outputField value="{!CPWR.Name}" /></b></p>                
                   <p align="Left"><b>  Project Type : <apex:outputField value="{!CPWR.Project_Type__c }" /></b></p>   
                    <p align="Left"><b>  No of Products: <apex:outputField value="{!CPWR.Total_Product_Qty__c}" /></b></p>  
                 
                 
               </div>
     <!-- ==== Header=== -->
    
    <!-- ==== Product Deatils=== -->
    
        
        <apex:outputText style="page-break-Before: Avoid; white-space:nowrap" > 
       
       
        <div class="Content" style="position:absolute; width:100% white-space:nowrap">
    
        <table style="font-size:13px;font-face:Arial;page-break-inside: avoid;white-space:nowrap " border="1" rules="cols" cellspacing="0" width="100%" cellpadding="0"  >
             
                <tr  height="30" width="100%" style="font-family: sans-serif; white-space:nowrap;font-weight: bold; font-size: 10pt;">
                                <th align="center">Sl.No</th>
                                 <th  align="center" > Product Name</th>
                                <th align="center">Required Material Name</th>
                                <th  align="center">Orginal Quantity</th>  
                                 <th  align="center">Quantity1</th>  
                                 
                </tr>      
            
                               <apex:variable value="{!0}" var="icount" />
                                <apex:repeat value="{!listdisprod }" var="line">
                                
                               <apex:variable value="{!icount+ 1}" var="icount" />
               <tr> 
                                <td style="text-align:center; " border-style="solid;"  width="10%"  >{!icount}.</td>  
                                <td width="10%" align="center"><apex:outputField value="{!line.Product__c}"/> </td>
                                <td width="10%" align="center">{!line.Name}</td>   
                                 <td width="10%" align="center">{!line.Quantity__c }</td>
                                 
                                  <apex:repeat value="{!listlinitem }" var="Qty">
                                
                                  <td width="10%" align="center">{!Qty.Quantity*line.Quantity__c}</td>
                                 </apex:repeat>   
                              
                                
                  </tr>            
                                  
              </apex:repeat>     
                 
                 
                                 
                                  
                                                                 
                                        
            
         </table>
        </div>
    
    </apex:outputText>    
                    
             
       
    </html>
    </apex:page>

Apex Class:
public class Dispatch_Workorder_Checklist {
public Project__c CPWR {get;set;}
list<OpportunityLineItem> listlinitem = New List<OpportunityLineItem>();
list<Dispatch_Product_Checklist__c> listdisprod = New List<Dispatch_Product_Checklist__c>();
Set<ID> setproducID = New Set<ID> ();
Map<ID,Decimal> ProdQty= New Map<ID,Decimal>();



    
    public list<Dispatch_Product_Checklist__c > getlistdisprod ()
    {
    Return listdisprod ;
    }
    
    public list<OpportunityLineItem > getlistlinitem()
    {
    Return listlinitem ;
    }

    public Dispatch_Workorder_Checklist(ApexPages.StandardController controller) {
    
    CPWR=[select ID,Name,Opportunity__c,Total_Product_Qty__c,Project_Type__c from Project__c  where ID=:ApexPages.CurrentPage().getParameters().get('Id')];
    listlinitem =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:CPWR.Opportunity__c  ];
    For(OpportunityLineItem opp: listlinitem )
    {    
    setproducID.add(opp.Product2Id );
   
    ProdQty.put(opp.Product2Id ,opp.Quantity);
      
    }
    
    listdisprod =[select ID,Name,Product__c,Quantity__c from Dispatch_Product_Checklist__c where Product__c=:setproducID]; 
      
    
    }
    
    

}

My Second Repeat should stop based first repeat. Kindly Help on this


User-added image
Expected Output



 
Hi All,

I have a product data  in  Quote line Item 

Product1
Product 2
Product 3

Based on this product i have to fetch a dispatch Check list for Each Product

When am trying display all the checklist together in Visulal Force Page.. I can able to see only one product Checklist.

Am unable to get all Checklist togther as a one Checklist? Kindly Guide me on this

My VF Page :
<apex:page renderAs="PDF" standardController="Project__c" extensions="Dispatch_Workorder_Checklist" applyBodyTag="False" ShowHeader="False"  applyHtmlTag="False">
<html>
  <head>
    <style>
        @page {
            
            margin-top: 2cm;
            margin-bottom: 2cm;
            margin-right:1CM;
             margin-Left:1CM;
              padding: 5px;
              
            @top-center {
                content: element(header);
            }
            @bottom-left {
                content: element(footer);
            }
        }

        div.header {
            width: 100%;
            padding: 5px;
            position: running(header);
        }
        div.footer {
            display: block;
            padding: 5px;
            position: running(footer);
        }
        .pagenumber:before {
            content: counter(page);
        }
        .pagecount:before {
            content: counter(pages);
        }
        div.content {
             border: 1px solid black;
             padding: 5px;
            width: 100%;
        }        
    </style>
</head>

 <!-- ==== Header=== -->
  
          <div class="header" >               
                <p align="center"><b>Dispatch Check List</b></p>
           </div>
 <!-- ==== Header=== -->

<!-- ==== Product Deatils=== -->
    <apex:outputText style="page-break-Before: Avoid; white-space:nowrap" > 
   
    <div class="Content" style="position:absolute; width:100% white-space:nowrap">

    <table style="font-size:13px;font-face:Arial;page-break-inside: avoid;white-space:nowrap " border="1" rules="cols" cellspacing="0" width="100%" cellpadding="0" >
         
            <tr  height="30" width="100%" style="font-family: sans-serif; white-space:nowrap;font-weight: bold; font-size: 10pt;">
                            <th align="center">Sl.No</th>
                            <th align="center">Required Material Name</th>
                            <th> Product Name</th>
                            <th>Quantity</th>  
            </tr>            
                           <apex:variable value="{!0}" var="icount" />
                           <apex:repeat value="{!listdisprod }" var="line">
                           <apex:variable value="{!icount+ 1}" var="icount" />
           <tr> 
                            <td style="text-align:center; " border-style="solid;"  width="10%"  >{!icount}.</td>  
                            <td width="10%" align="center">{!line.Name}</td>
                            <td width="10%" align="center"><apex:outputField value="{!line.Product__c}"/> </td>
                            <td width="10%" align="center">{!line.Quantity__c }</td>
                                    
           </tr>
                 
          </apex:repeat>
         
                    
     </table>
    </div>

</apex:outputText>                         
         
   
</html>
</apex:page>


My Apex Clas:
public class Dispatch_Workorder_Checklist {
public Project__c CPWR {get;set;}
list<OpportunityLineItem> listlinitem = New List<OpportunityLineItem>();
list<Dispatch_Product_Checklist__c> listdisprod = New List<Dispatch_Product_Checklist__c>();
public list<Dispatch_Product_Checklist__c > getlistdisprod ()
{
Return listdisprod ;
}



    public Dispatch_Workorder_Checklist(ApexPages.StandardController controller) {
    
    CPWR=[select ID,Name,Opportunity__c from Project__c  where ID=:ApexPages.CurrentPage().getParameters().get('Id')];
    listlinitem =[select ID,Product2Id from OpportunityLineItem where OpportunityID=:CPWR.Opportunity__c  ];
    listdisprod =[select ID,Name,Product__c,Quantity__c from Dispatch_Product_Checklist__c where Product__c=:listlinitem[0].Product2Id ];    
  
    }

}

Out to get all product checklist together as one page in VF

Thanks,
Shakila
 

Hi All,
I have a detail page Button(VF) to create a Components records for the parent record in standard Page.

After entering a input in VF page, If I press the Enter Key button before saving the record...automatically it's redirecting to the parent record page.

Due to this, I Lost my All Input values.Kindly Assist me to overcome this issue.

My VF page :

<apex:page standardController="Product2" extensions="AddProductComponent">


    <apex:form >
    
        

        <apex:pageMessages id="err"></apex:pageMessages>
      
       <apex:pageBlock title="Product Informations">
          
       <div align ="Right"> <apex:commandButton value="Back" action="{!Cancel}" /> </div>
        <table width="80%">
        <tr>
        <td>Product name</td>
        <td>{!Product2.name}</td>
        </tr>
        <tr>
        <td>Product Code</td>
        <td>{!Product2.ProductCode}</td>
        </tr>
        <tr>
        <td>Product Category</td>
        <td>{!Product2.Family}</td>
        </tr>
        </table>
   
        <apex:pageblockButtons location="bottom" >
        <apex:inputtext value="{!addCount}"/>
        <apex:commandButton value="Add Row" action="{!addRows}" rendered="{!show1}"/>
        
        </apex:pageblockButtons>
          <apex:pageblockButtons location="bottom">
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!Cancel}"/>
        </apex:pageblockButtons>
        
        </apex:pageBlock>
          
        <apex:pageBlock title="Component Informations" rendered="{!show1}" >  
        <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
        <apex:column headerValue="Ident">
        <apex:outputText value="{!wrapper.ident}"/>
        </apex:column>
        
      <apex:column headerValue="Raw Material Name">
        <apex:inputField value="{!wrapper.bkmas.Raw_Material__c}">    
        </apex:inputField>        
         </apex:column> 
      
        
        <apex:column headerValue="Measurement">
        <apex:inputfield value="{!wrapper.bkmas.Measurement__c}"/>
        </apex:column>
        
        <apex:column headerValue="Quantity">
        <apex:inputfield value="{!wrapper.bkmas.Quantity__c}"/>
        </apex:column>
        
        <apex:column headerValue="Description">
        <apex:inputfield value="{!wrapper.bkmas.Description__c}"/>
        </apex:column>
        </apex:pageBlockTable>
        
      
        </apex:pageBlock>
        

    </apex:form>
</apex:page>

Apex Class:

public class AddProductComponent {

   //Declarartions
    List<Product2> LstProduct = new List<Product2>();
    List<Component__c> lstComp = new List<Component__c>(); 
    String RecId;
    
    public static Integer addCount {get; set;}
    private Integer nextIdent=01;
    List<Innerclass> wrappers = new  List<Innerclass>();
    boolean show = true;
    boolean show1 = true;
    
    public AddProductComponent(ApexPages.StandardController controller) {
        RecId = ApexPages.currentPage().getParameters().get('id');
        LstProduct = [Select Id,Name,ProductCode,Family,Total_No_of_Raw_Materials__c
                      from Product2 where id=:RecId];
        lstComp  = [select id,Name,Raw_Material__c,Quantity__c,Measure_Unit__c,Description__c, 
                    Product__c ,Measurement__c,Raw_Material__r.Code__c, RawMaterial_Code__c from Component__c where Product__c =: RecId];
        
        if(lstComp.size()<=0){
            addRows();
        }
        else {
            show1 = false;
            Message();
        }            
        
    }
    
    public boolean getshow()
    {
         return show;
    }
    
    public boolean getshow1()
    {
         return show1;
    }
    
    public List<Innerclass> getwrappers()
    {
    return wrappers;
    }
   
    Public Void Message(){
       
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'You cannot enter Components to this Product, Please use Edit Component Button'));
    }
    
    public void addRows()
    {   
        for (Integer idx=0; idx<addCount; idx++)
        {
        wrappers.add(new Innerclass(nextIdent++));
        }
    }
    
    
    public pagereference save()
    {
        List <Component__c>  lstcomp =  new List <Component__c>();
        for(Innerclass wrap:wrappers)
        {
            Component__c component =  new Component__c();
            string ident = string.valueof(wrap.ident);
            if(ident.length()== 1) {
                 component.Name = '0'+ ident;
            } else{
                component.Name = ident;
            }
            component.Raw_Material__c = wrap.bkmas.Raw_Material__c;
            component.Quantity__c = wrap.bkmas.Quantity__c;
            component.Description__c = wrap.bkmas.Description__c;
            component.RawMaterial_Code__c = wrap.bkmas.RawMaterial_Code__c;
            component.Measurement__c = wrap.bkmas.Measurement__c;
            component.Product__c = Recid;
            lstcomp.add(component);
        }
        try {
            insert lstcomp;
            PageReference acctPage = new PageReference ('/' + RecId);
            acctPage.setRedirect(true);
            return acctPage;   
        } catch (exception ex) {
            apexpages.message err = new apexpages.message(apexpages.severity.ERROR,ex.getmessage());
            apexpages.addmessage(err);
            return null;
        }
    }
    
    
   //Intermediate Class()
    public class Innerclass
    {
    public string CustomId;
    public Component__c bkmas {get; private set;}
    public Integer ident {get; private set;}
        public Innerclass(Integer inIdent)
        {

        ident=inIdent;
        bkmas =new Component__c ();
        }
    }
}

 

Hi All,

We have Integrated the third party Call Center API with Salesforce.

In CTI integration, If the Existing customer Calls come through IVR My Salesforce API will return the response of the respective customer user ID to the third party.
So that the customer Calls will land to the respective user system. Once the customer call received in salesforce respective customer page will open automatically in the user system.

If the New Customer tried to call, the new customer Calls will land to the respective user system. Once the Calls received in salesforce for new customers, it's automatically it's creating the new contact record in Salesforce.

But I would like to stop the automatic record creation for the new customers.

Kindly assist me on this.

Thanks
Shakila
Hi All,
I have different mobile filed in lead and Account as well contact. The mobile field may contains start with zero or without Zero. So i want to find only last 10 digits in Apex class. So that I can compare the last 10 digit number with the input values.

LstAct=[SELECT Owner.Email FROM Account where (Phone=:Mobile_No   or Mobile__c=:Mobile_No OR Mobile1__c=:Mobile_No OR Mobile2__c=:Mobile_No OR Phone_Additional__c =:Mobile_No)];

Kindly  give me the suggestion to solve this issue

Thanks,
Shakila
Hi All,

I want to send  a record third party Application..whenever the records getting created in salesforce.

KIndly provide me some solution how to send it .
I have 5 mobile fields in lead object
To avoid the lead duplicate I have to check all the 5 fields with each other

This my code is trying to check the duplicates. Is the correct way to check the duplicates?

Trigger leadduplicatecheck on lead(before insert,Before Update)
{

List<Lead> llist=new list<lead>();

Set<string> setMobilePhone =new set<String>();
Set<string> setWhatsapp =new set<String>();
Set<string> setMobile =new set<String>();
Set<string> setPhone     =new set<String>();
Set<string> setPhoneAdd =new set<String>();

for(Lead l:Trigger.new)
{
setMobilePhone.add(l.MobilePhone);
setWhatsapp.add.(l.Whatsapp_Mobile__c);
setMobile.add.(l.Mobile_Additional__c);
setPhone.add.(l.Phone);
setPhoneAdd.add.(l.Phone_Additional__c);

}

llist=[select ID from Lead where (MobilePhone =:setMobilePhone or MobilePhone=:setWhatsapp
MobilePhone =:setMobile or
MobilePhone =:setPhone or
MobilePhone =:setPhoneAdd  ) OR

(Phone =:setMobilePhone or
 Phone=:setWhatsapp or
Phone =:setPhone or
Phone =:setMobile or
Phone =:setPhoneAdd ) OR


(Mobile_Additional__c =:setMobilePhone or
 Mobile_Additional__c=:setWhatsapp or
Mobile_Additional__c =:setPhone or
Mobile_Additional__c =:setMobile or
Mobile_Additional__c =:setPhoneAdd ) OR

(Whatsapp_Mobile__c =:setMobilePhone or
 Whatsapp_Mobile__c=:setWhatsapp or
Whatsapp_Mobile__c =:setPhone or
Whatsapp_Mobile__c =:setMobile or
Whatsapp_Mobile__c =:setPhoneAdd ) OR

(Phone_Additional__c =:setMobilePhone or
 Phone_Additional__c=:setWhatsapp or
Phone_Additional__c =:setPhone or
Phone_Additional__c =:setMobile or
Phone_Additional__c =:setPhoneAdd )];



For(Lead l : Trigger.New)
{
if(Trigger.isupdate &&llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber, Duplicate');

}

if(Trigger.insert  && llist.size()>0)
{
l.adderror('Already Lead Exist with this Mobile Nuber');

}
}   
}


 
Hi All,

In lightnin page am using two submit button. 
1.Save
2.Save and New
When user click on save  based on handle on success am navigating new record detial page.
when user clicks save and new am unable to navigate to new screen that also going to same record details page.

How to handle two method seprately on success?

Thanks in Advance
Argument cannot be null in Apex class
Hi All,

When the Belowmethod called through VF page button , SOme time am getting below error

Argument cannot be null.

Error is in expression '{!addworkorders}' in component <apex:commandButton> in page check_available_rawmaterials: Class.Check_Available_Rawmaterials.addworkorders: line 49, column 1
Which is Highlightes as Bold in the below mentioned code

Kindly please help me to over come from this issue
 public void addworkorders() {
        AttachmentCallWrapperlist3.clear();
        setprodid.clear();
        setRMid.clear();
        lstrmri.clear();
        lstComp .clear();
        //wraplist.clear();
        //Result.clear();
        //Result1.clear();
        //Result2.clear();
        iRmInvLst.clear();
        AttachmentCallWrapperlist.clear();
        AttachmentCallWrapperlist3.clear();
         Productnamemap.clear();
        Productqtymap.clear();
            
        show = true;
        /*for (Project__c iRow:lstworkorder) {if (iRow.Selected__c == true) {   setRMid.add(iRow.Opportunity__c);
            } 
        }   */                     
        Boolean isTrue = TRUE;
        IF(setprojectid!=Null){
            lstrmri =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:setprojectid]; 
            IF(lstrmri .size()>1){
            For(OpportunityLineItem  olt:lstrmri ){ 
            setprodid.add(olt.Product2Id);
                }
            }                          
        }  
        If(lstrmri.size()>0) { wraplist=new List<AddWrapperField1>();  
            Result=[select SUM(Quantity) Totalqty,Product2.name ProdName from OpportunityLineItem where opportunityID=:setprojectid      group By Product2.name];                          
            
            IF(Result.size()>0){
            for(AggregateResult res:Result){   wraplist.add(new AddWrapperField1(Res)); 
                Productqtymap.put((String)res.get('ProdName'), (Decimal)res.get('Totalqty'));
            }   
            }
        }  
        IF(setprodid!=Null){
            lstComp =[select ID,name,Raw_Material__c,Selected__c,Product__R.name,Total_Measurement__c  from Component__c where Product__r.name in : Productqtymap.keyset()];
            If(lstComp .size()>0) {
                wraplist1=new List<AddWrapperField>();         
                Result1=[select SUM(Total_Measurement__c) TotalMeasure,Raw_Material__r.name Name,Product__r.name pName  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Product__r.name,Raw_Material__r.name]; 
                Result2=[select Raw_Material__r.name Name  from Component__c  where Product__r.name in : Productqtymap.keyset()
                         group By Raw_Material__r.name]; 
                     IF( Result1.SIZE()>0 && Productqtymap!=Null){
                          for(AggregateResult res2:Result1){  
                 Rawmaterialmap.put((string)res2.get('Name'),(Double)res2.get('TotalMeasure')* Productqtymap.Get((String)res2.get('pName')));
                 }
            }  
            If(Result1.size()>0 && Productqtymap!=NUll && Rawmaterialmap!=Null ){
                for(AggregateResult res1:Result1){ 
                    AttachmentCallWrapper I= New AttachmentCallWrapper();  
                    i.qty=0; 
                    i.RequiredMaterial =(string)res1.get('Name'); 
                       If(Rawmaterialmap.size()>0){
                       i.Qty=Rawmaterialmap.get((string)res1.get('Name')); }
                    i.ProductName =(string)res1.get('pName');             
                    i.ProdutQty  = Productqtymap.Get((String)res1.get('pName')); 
                    AttachmentCallWrapperlist.add(i);            
                } 
                
                }
                
                if(AttachmentCallWrapperlist.size()>0 && Productqtymap!=Null){
                For(AttachmentCallWrapper  atc: AttachmentCallWrapperlist){           
                    if (Productqtymap.containskey(atc.RequiredMaterial)){            
                        Productqtymap.put(atc.RequiredMaterial,
                        (atc.Qty+ Productqtymap.get(atc.RequiredMaterial)) );     
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);         
                    }Else{
                        Productqtymap.put(atc.RequiredMaterial, atc.Qty);
                        Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);    
                    }
                }
            }
        }  
        
        }
        iRmInvLst=[SELECT id,Name,RawMaterial__c,Available_RM_in_OrigMeasure__c ,Unit__c FROM Raw_Material_Inventory__c 
                   WHERE Name IN :Productnamemap.keyset()];
        IF(iRmInvLst.Size()>0 && Productqtymap!=Null){
            For(Raw_Material_Inventory__c INV: iRmInvLst){
                AttachmentCallWrapper2 atc4 = new AttachmentCallWrapper2();
                atc4.RequiredMaterial=INV.NAME;  
                atc4.Stock=INV.Available_RM_in_OrigMeasure__c;
                if(INV.Available_RM_in_OrigMeasure__c<Productqtymap.get(INV.NAME)){
                atc4.Requiredqty=Productqtymap.get(INV.NAME)-INV.Available_RM_in_OrigMeasure__c;
                    atc4.PurchaseUnit=INV.Unit__C;
                }
                atc4.Qty=Productqtymap.get(INV.NAME);   AttachmentCallWrapperlist3.add(atc4);
                
            }
        }
    }

Thanks,
Shakila
Hi All,

Am trying to group the table values in lightning component.Please help me on this to resolve this issue.

How to aggregate the bewlo field values. After aggragte I need to display a single row for each group in Lightning component.
any one can help on this?

User-added image

Thanks,
Shakila
HI All,

Am trying to simplify the sales force Mobile Users objects layout.
If the user logged in the browser it should be actual page layout. If the same user logged in Mobile App should be a Simplified layout.
How to display a different page layout for Mobile and browser based.

Kindly assist me how to accomplish this.


Thanks,
Shakila
 
Hi All,

I want to send  a record third party Application..whenever the records getting created in salesforce.

KIndly provide me some solution how to send it .
HI All,

Am trying to fetch Custom object related Approval process records information from processinstance step using soql workbecn.
Select Account__r.Name,Team_Member__r.Name ,Team_Member__r.ISActive,Team_Member_Email__c,Team_Role__c, Status__c,RHMS_Approval_Status__c, Approval_Status__c ,(SELECT ProcessInstance.TargetObjectId ,Comments FROM ProcessInstanceStep)from Account_Team__C
where ID='a4Qc0000000kBDt'

Am getting following error..

Didn't understand relationship 'ProcessInstanceStep' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Kindly let me know ..How to fetch alll those records using workbench..
Hi All,

I created a new field in user with the data type number am trying to update the field called Total License from user license object .

to acomplish this i wrote a bacth class.But its not updating this field.

Kindly let mw know ,Where i do changes
Batch Class:
global class totallicensecount implements Database.Batchable<SObject>{
Map<ID,String> License= New Map<ID,String>();
Map<string,Integer> License1= New Map<string,Integer>();
list<user> query1=new list<user>();
set<string> setuserlicense=new set<string>();
list<user> listofuser=new list<user>();

        
        global Database.QueryLocator start(Database.BatchableContext bc){
                string query='select Id,name,TotalLicenses from Userlicense'; 
                query+='limit 1';       
                return Database.getQueryLocator(query);
        
        }
        

        global void execute(Database.BatchableContext bc,list<Userlicense> scope){
        
                for(Userlicense us:scope){
                License1.put(Us.Name,us.TotalLicenses);
                setuserlicense.add(us.name);
                }
            
                    query1=[select Id,name,profile.Userlicense.name,Profile.UserLicense.TotalLicenses,Type__C,Total_license_count__c from user where profile.Userlicense.name in :setuserlicense];
                    for(user us1:query1){
                    us1.Total_license_count__c=License1.get(us1.profile.Userlicense.name);
                    listofuser.add(us1);                   
                   
                }
            
        IF(listofuser.size()>0){
        
        update listofuser;
        
        }
}



global void finish (Database.BatchableContext bc){
}



}


 
Hi All,

I have written a trigger to update both opportunity and cumulative object.
My logic is working fine for the same I have written a test class. My code coverage is 81 % in Sandbox when I go for deployment in production ...during the validation am getting following error. Kindly let me know How to overcome from the below error.

User-added image
My trigger:

trigger UpdateAmountInWords on Opportunity (Before Update) {
List<Target__C> Tglist= New List<Target__C>();
List<Target__C> Tglist1= New List<Target__C>();
Map<String,ID> Mapfield = New map<String,ID>();
Map<String,ID> MapTele = New map<String,ID>();
List<Incentive__c >lstInc =New list<Incentive__c >();
List<Incentive__c >lstInc1 =New list<Incentive__c >();
List <Cumulative__c> Cumlist= New list <Cumulative__c>();
List <Cumulative__c> Cumlist1= New list <Cumulative__c>();
list<Cumulative__c > lstcum = new list<Cumulative__c >(); 
list<Opportunity > opplist = new list<Opportunity >(); 
 Utils u = new Utils();
       For(Opportunity opp:Trigger.New){ 
       // Update opporunity Amount In Words
        opp.Amount_To_Words_Total_Amount_With_Tax__c = u.convert(opp.Total_Amount_With_IGST__c.longValue())+' Only'; 
        opp.Amount_To_Words_Total_Tax_Amount__c = u.convert(opp.Total_Tax_Amount__c.longValue())+' Only'; 
        //            
       Mapfield .put(opp.Field_Executive__c,opp.ID);MapTele.put(opp.Hidden_Owner_Name__c,opp.ID);}
       
TGlist1=[select ID, name from target__C where Name in:Mapfield.keyset() and Active__c=True];           
TGlist=[select ID, name from target__C where Name in:MapTele.keyset() and  Active__c=True];
            for(Opportunity opp: trigger.new ) { 
                    if(TGlist1.size()>0){if(opp.Field_Executive__c==TGlist1[0].NAme){
                                   opp.Target__C= TGlist1[0].ID; } }
                    IF(TGlist.size()>0){if(opp.Hidden_Owner_Name__c==TGlist[0].NAme){   
                                   opp.Telecaller__c=TGlist[0].ID;}}         
            If(opp.Telecaller__c!=Null && opp.Cumulative_Updated__c==False && opp.Work_Order_Created_Date__c!=Null ){
              Cumlist=[select ID,Target__c,Type1_Customer_Order_value_MPD__c,Type1_Customer_Order_Value_PD__c,Type2_Customer_Order_value_MPD__c,Type2_Customer_Order_value_PD__c,Type3_Customer_Order_value_MPD__c,Type3_Customer_Order_value_PD__c,Type4_Customer_Order_value_MPD__c,Type4_Customer_Order_value_PD__c,From_Date__c,To_Date__c from Cumulative__c where Target__c=:opp.Telecaller__c and  From_Date__c<=:opp.Work_Order_Created_Date__c and To_Date__c>=:opp.Work_Order_Created_Date__c];
                   if(Cumlist.size()>0){For(Cumulative__c Cum:Cumlist){lstInc = [select ID from Incentive__c where ID =:Opp.IncentiveSlab__c and Opp_Discount_To__c>=:opp.Discount__c]; 
                        If(lstInc.size()>0 ){If(Opp.Customer_Slab_Type__c=='Type 4'){           
                                Cum.Type4_Customer_Order_value_PD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 2'){Cum.Type2_Customer_Order_value_PD__c+= opp.Individual_Order_value__c; opp.Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 3'){Cum.Type3_Customer_Order_value_PD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 1'){Cum.Type1_Customer_Order_Value_PD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                             }} IF(lstInc.size()<=0 ){If(Opp.Customer_Slab_Type__c=='Type 4'){Cum.Type4_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                            }Else IF(Opp.Customer_Slab_Type__c=='Type 2'){Cum.Type2_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                            }Else IF(Opp.Customer_Slab_Type__c=='Type 3'){Cum.Type3_Customer_Order_value_MPD__c += opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                            } Else IF(Opp.Customer_Slab_Type__c=='Type 1'){Cum.Type1_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c;opp.Cumulative_Updated__c=True;
                            } }lstcum .add(Cum);opplist.add(opp);} } } 
         If(opp.Target__C!=Null && opp.FE_Cumulative_Updated__c==False && opp.Work_Order_Created_Date__c!=Null ){               
              Cumlist1=[select ID,Target__c,Type1_Customer_Order_value_MPD__c,Type1_Customer_Order_Value_PD__c,Type2_Customer_Order_value_MPD__c,Type2_Customer_Order_value_PD__c,Type3_Customer_Order_value_MPD__c,Type3_Customer_Order_value_PD__c ,Type4_Customer_Order_value_MPD__c,Type4_Customer_Order_value_PD__c,From_Date__c,To_Date__c from Cumulative__c where Target__c=:opp.Target__C and From_Date__c<=:opp.Work_Order_Created_Date__c and To_Date__c>=:opp.Work_Order_Created_Date__c];
               if(Cumlist1.size()>0){For(Cumulative__c Cum:Cumlist1){ 
                       lstInc1 = [select ID from Incentive__c where ID =:Opp.IncentiveSlab__c and Opp_Discount_To__c>=:opp.Discount__c]; 
                        If(lstInc1.size()>0 ){If(Opp.Customer_Slab_Type__c=='Type 4'){ Cum.Type4_Customer_Order_value_PD__c+= opp.Individual_Order_value__c;opp.FE_Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 2'){Cum.Type2_Customer_Order_value_PD__c+= opp.Individual_Order_value__c;opp.FE_Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 3'){Cum.Type3_Customer_Order_value_PD__c += opp.Individual_Order_value__c; opp.FE_Cumulative_Updated__c=True;
                             }Else IF(Opp.Customer_Slab_Type__c=='Type 1'){Cum.Type1_Customer_Order_Value_PD__c+= opp.Individual_Order_value__c;   opp.FE_Cumulative_Updated__c=True;
                             }} IF(lstInc1.size()<=0 ){ If(Opp.Customer_Slab_Type__c=='Type 4'){Cum.Type4_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c; opp.FE_Cumulative_Updated__c=True;
                        }Else IF(Opp.Customer_Slab_Type__c=='Type 2'){ Cum.Type2_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c; opp.FE_Cumulative_Updated__c=True;
                        }Else IF(Opp.Customer_Slab_Type__c=='Type 3'){ Cum.Type3_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c; opp.FE_Cumulative_Updated__c=True;
                        } Else IF(Opp.Customer_Slab_Type__c=='Type 1'){Cum.Type1_Customer_Order_value_MPD__c+= opp.Individual_Order_value__c;opp.FE_Cumulative_Updated__c=True;}        
                        }lstcum .add(Cum); opplist.add(opp);
                      } } } 
                      update lstcum ; }}

 
Hi All,
Am trying to Writrive all the opportunity records based on month given as an Input though VF page.

How to get the Input value from VF to Apex Class?

My APex Class
public with sharing class updateincentive {
 Opportunity opp;
 Public  Integer Thismonth {Get;Set;}
    public updateincentive(ApexPages.StandardSetController controller) {
     opp = (Opportunity) controller.getRecord();   
     
    }

    public List<Opportunity> getFinalPayOpp() {
         
        return [select Name,Hidden_Project_Created__c,Customer_Slab_Type__c,IncentiveSlab__c,NewIncentivePercentage__c,Incentive_Amount__c,Incentive_For__c,No_of_Days__c,Date__c
              from Opportunity where CALENDAR_MONTH(Final_Full_Payment_Date__c)=:Thismonth and  Hidden_Final_Pay_Created__c=True  ];
     
    }                                    
}

 
Hi All,

My Apex Class still giving the 72 % percentage. Kindly let the optimized way to get more than 75% 


My Test class :

@isTest(seealldata=true)
private class OI_Incentivetest{
    static testMethod void IO_IncentiveIfillINCalculus(){
    
        GetInitialData Getdata = new GetInitialData();
        list<Account> acc = Getdata.getAccount();
        list<Product2> lstprod = Getdata.getProd();
        list<Opportunity> Opp = Getdata.getOpp();
        list<Pricebook2> lstPB = Getdata.getpricebook();
        list<Pricebookentry> lststdPbe = Getdata.getstdpbe();
        list<Pricebookentry> lstPbentry = new list<Pricebookentry>();
        list<attachment> lstattachment =  new list<attachment>();
        insert lstprod; 
        
        Incentive__c incindoor= new Incentive__c(Name='Indoor test', Active__c = true, Product_Type__c = 'Indoor', 
                Start_Date__c = date.newinstance(2014,12,25), Area__c = 'All India');
        insert incindoor;
        
        IncentiveLineItem__c inclitem = new IncentiveLineItem__c(Incentive__c = incindoor.id,Other_Mode__c=0.80 ,Neft_Cash__c=0.75 , Discount_From__c=0,Discount_To__c=10,Field_Staff__c=1,Telesales__c=1,Combined__c=2);
        IncentiveLineItem__c inclitem1 = new IncentiveLineItem__c(Incentive__c = incindoor.id,Other_Mode__c=0.80 ,Neft_Cash__c=0.75 , Discount_From__c=10,Discount_To__c=20,Field_Staff__c=0.5,Telesales__c=.05,Combined__c=1);
        insert inclitem;
        insert inclitem1;
        
        Incentive__c incPE= new Incentive__c(Name='PE test', Active__c = true, Product_Type__c = 'Play Equipment', Start_Date__c = date.newinstance(2014,12,25), Area__c = 'South');
        insert incPE;
        
        IncentiveLineItem__c incpeitem = new IncentiveLineItem__c(Incentive__c = incPE.id,Other_Mode__c=0.80 ,Neft_Cash__c=0.75 ,Discount_From__c=0,Discount_To__c=10,Field_Staff__c=1,Telesales__c=1,Combined__c=2);
        IncentiveLineItem__c incpeitem1 = new IncentiveLineItem__c(Incentive__c = incPE.id,Other_Mode__c=0.80 ,Neft_Cash__c=0.75 , Discount_From__c=10,Discount_To__c=20,Field_Staff__c=0.5,Telesales__c=.05,Combined__c=1);
        insert incpeitem;
        insert incpeitem1; 
        
        Integer indexvalue = 0;
        if(lstprod.size()>0){
            for(pricebookentry irow :lststdPbe){
                irow.product2id = lstprod[indexvalue].id;
                indexvalue++;
            }
        }
        
        insert lststdPbe;
        insert lstPB; 

        if(lstprod.size()>0)  {
            for(pricebook2 irow :lstPB) {
                for(Product2 ipro : lstprod ){
                    Pricebookentry pbe = new Pricebookentry();
                    pbe.product2id = ipro.id;
                    pbe.pricebook2id = irow.id;
                    pbe.unitprice = 3000;
                    pbe.isActive = true;
                    lstPbentry.add(pbe);    
                }
            }
        }
        
        insert lstPbentry;
        insert acc[0];
       
        Opp[0].accountId = acc[0].id;
        insert Opp[0]; 
        
        //Test.startTest();
        lstPB[0].Incentive_Slab__c=incPE.ID;
         update lstPB[0];
        
        Opp[0].Pricebook2Id = lstPB[0].id;
        update Opp[0];
        
        
        
        OpportunityLineItem OL = new OpportunityLineItem(opportunityid=Opp[0].id, Quantity=1, unitprice=8000,  
        pricebookentryid=lstPbentry[0].id);
        insert OL;  
        
        Quote Q = new Quote();
        Q.Name = 'QuoteOrbit';
        Q.OpportunityId = Opp[0].id; 
        Q.Quote_Count__c = 77;
        Q.Approved__c = true;
        Q.Quote_Number__c ='00000710';
        Q.Quotation_Date__c = date.newinstance(2013,3,5);
        Q.Pricebook2Id = lstPB[0].id;
        insert Q;
        
        Quotelineitem QL = new Quotelineitem(quoteId=Q.id, Quantity =1, Unitprice=8000,pricebookentryid=lstPbentry[0].id);
        insert QL; 
        
        Opp[0].SyncedQuoteId = Q.id;
        update Opp[0];
       
        Opp[0].Stagename = 'Closed Won';
        update Opp[0];
        
        Project__c Proj = new Project__c(name='OrbitProj', Opportunity__c = Opp[0].id, Quote__c = Q.id, Project_Type__c = 'New PE', Date_of_Installation__c = date.newinstance(2013,4,5),
        Nature_of_Case__c ='No Adv, Dspch & Erection Pending',Customer_Name__c=acc[0].id,Special_Instructions__c ='Test for Work order Pdf to be generated');    
        
        insert Proj;
        
        Payment__c pay = new Payment__c( Amount__c = 8400, Date__c = date.newinstance(2013,4,25),Project__C=Proj.ID ,Mode_of_Payment__c = 'Cheque',Opportunity__c = Opp[0].id, Payment_Type__c ='Full Pay');
        insert pay;    
       
        
      
       
       
        Opp[1].accountId = acc[0].id;
        insert Opp[1]; 
        
         lstPB[1].Incentive_Slab__c=incPE.ID;
         update lstPB[1];
       
        
        Opp[1].Pricebook2Id = lstPB[1].id;
        update Opp[1];
        
         Opp[1].Incentive_Calculated__c = true;
         Opp[1].NewIncentivePercentage__c=incpeitem1.Field_Staff__c;
        Update Opp[1];
        
        OpportunityLineItem OL1 = new OpportunityLineItem(opportunityid=Opp[1].id, Quantity=1, unitprice=25000,  
        pricebookentryid=lstPbentry[8].id);
        insert OL1;  
       
        Quote Q1 = new Quote();
        Q1.Name = 'QuoteOrbit';
        Q1.OpportunityId = Opp[1].id; 
        Q1.Quote_Count__c = 7;
        Q1.Approved__c = true;
        Q1.Quote_Number__c ='00000010';
        Q1.Quotation_Date__c = date.newinstance(2013,3,5);
        Q1.Pricebook2Id = lstPB[1].id;
        
        insert Q1;
        
        Quotelineitem QL1 = new Quotelineitem(quoteId=Q1.id, Quantity =1, Unitprice=25000,pricebookentryid=lstPbentry[8].id);
        insert QL1; 
         
        Opp[1].SyncedQuoteId = Q1.id;
        update Opp[1];
        
        Opp[1].Stagename = 'Closed Won';
        update Opp[1];
        
        Test.startTest();
        
        Project__c Proj1 = new Project__c(name='OrbitProj', Opportunity__c = Opp[1].id, Quote__c = Q1.id, Project_Type__c = 'New PE', Date_of_Installation__c = date.newinstance(2013,4,10),
        Nature_of_Case__c ='No Adv, Dspch & Erection Pending',Customer_Name__c=acc[0].id,Special_Instructions__c ='Test for Work order Pdf to be generated');    
        insert Proj1;
        
        Payment__c pay1 = new Payment__c( Amount__c = 5000, Date__c = date.newinstance(2013,4,15),Project__C=Proj1.ID, Mode_of_Payment__c = 'Cheque',Opportunity__c = Opp[1].id, Payment_Type__c ='Advance');
        insert pay1; 
        
        Payment__c pay2 = new Payment__c( Amount__c = 21790, Date__c = date.newinstance(2013,4,20),Project__C=Proj1.ID, Mode_of_Payment__c = 'Cheque',Opportunity__c = Opp[1].id, Payment_Type__c ='Final Pay');
        insert pay2; 
        
       iF(pay2.Payment_Type__c =='Final Pay')
       
       opp[1].IncentiveSlab__c=incPE.ID;
       Update opp[1];
        
        
        // Third Opportunity lstOpp[1]//
        Opp[2].accountId = acc[0].id;
        insert Opp[2];         
       
      

        Opp[2].Pricebook2Id = lstPB[2].id;
        update Opp[2];
        
        OpportunityLineItem OL2 = new OpportunityLineItem(opportunityid=Opp[2].id, Quantity=1, unitprice=25000,  
        pricebookentryid=lstPbentry[16].id);
        insert OL2;  
       
        Quote Q2 = new Quote();
        Q2.Name = 'QuoteOrbit';
        Q2.OpportunityId = Opp[2].id; 
        Q2.Quote_Count__c = 14;
        Q2.Approved__c = true;
        Q2.Quote_Number__c ='0000110';
        Q2.Quotation_Date__c = date.newinstance(2013,3,5);
        Q2.Pricebook2Id = lstPB[2].id;
        insert Q2;
        
        Quotelineitem QL2 = new Quotelineitem(quoteId=Q2.id, Quantity =1, Unitprice=30000,pricebookentryid=lstPbentry[16].id);
        insert QL2; 
         
        Opp[2].SyncedQuoteId = Q2.id;
        update Opp[2];
        
        Opp[2].Stagename = 'Closed Won';
        update Opp[2];
        
        Project__c Proj2 = new Project__c(name='OrbitProj', Opportunity__c = Opp[2].id, Quote__c = Q2.id, Project_Type__c = 'New PE', Date_of_Installation__c = date.newinstance(2013,4,10),
        Nature_of_Case__c ='No Adv, Dspch & Erection Pending',Customer_Name__c=acc[0].id,Special_Instructions__c ='Test for Work order Pdf to be generated');    
        insert Proj2;
          
        Payment__c payproj1 = new Payment__c ( Amount__c = 32149, Date__c = date.newinstance(2013,4,15),Project__C=Proj2.ID, Mode_of_Payment__c = 'Cheque',Opportunity__c = Opp[2].id, Payment_Type__c ='Full Pay');
        insert payproj1; 
        
        
     
        // Test For Trigger Incentive Claculus
        Opp[0].Incentive_Calculated__c = true;
        Update Opp[0];
        
        Opp[0].IncentiveSlab__c = incindoor.id;
        update Opp[0];

       
        
         lstPB[2].Incentive_Slab__c=incPE.ID;
         update lstPB[2];
        
        
        Opp[2].IncentiveSlab__c = incindoor.id;
        Update Opp[2];
        
        
        
        
       
        Test.stopTest();
    }
}


My Trigger:

trigger Incentive_Slot on Payment__c (after insert, after update) {

    Set<Id> OppId = new Set<Id>();
    List<Opportunity> opplist = new List<Opportunity>();
    set<Id> PBname = new set<Id>();
    List<Incentive__c> inc = new List<Incentive__c>(); 
    list<IncentiveLineItem__c> lstIli = new list<IncentiveLineItem__c>();
    Date pDate;
    ID ProjectiD;
    List<Pricebook2> PB= new List<Pricebook2>(); 
    Map<Id,Id>     incMap = new Map<id,id>();
    List<Opportunity> OppListtoUpdate = new List<Opportunity>();
    Integer NofoDays = 0;
    Boolean IFlag;
   
    set<String> PType =new set<String>();
     set<ID> PAYID=new set<ID>();
    for(Payment__c pRow: Trigger.new) {
        if( (prow.Payment_Type__c == 'Full Pay') || (prow.Payment_Type__c == 'Final Pay')) {
            OppId.add(prow.Opportunity__c);
              pDate = prow.Date__c;
              ProjectiD=Prow.Project__C;
              Ptype.add(Prow.Payment_Mode_Type__c);
              PAYID.add(Prow.ID);
        } 
    }
    
    
    
    
    if(OppId.size() > 0)
    {
        opplist = [select id, Customer_Slab_Type__c,Discount__c,StageName, Work_Order_Date__c, Date__c, Pricebook2Id, Pricebook_Name__c, 
            IncentiveSlab__c, Last_Payment_Received_Date__c, Incentive_For__c, Incentive__c,
            NewIncentivePercentage__c, IncentiveLast_Payment_Date__c, Final_Full_Payment_Date__c, 
            Outstanding_Amount__c, Special_Incentive_Account__c from Opportunity where id IN : OppId]; 
    }
    
    If(opplist.size() > 0)
    {
        for(Opportunity o : opplist)
        {
            if (o.StageName=='Closed Won' && o.Pricebook2Id!= null) {
                PBname.add(o.Pricebook2Id);
            }

        }
    }
    
    
    
    if(PBname.size() > 0)
    {
    
        PB=[select ID,Incentive_Slab__c from Pricebook2 where ID in :PBname and IsActive=True];
        {
        
        for(Pricebook2 i: PB)
        {
            if(i.Incentive_Slab__c != null)
            incMap.put(i.ID,i.Incentive_Slab__c);
        
        }
        
          }
    
    }
    
    
    
    for(Opportunity op : opplist)
    {   
        if (op.StageName=='Closed Won' && op.Pricebook_Name__c != null && incMap.containskey(op.Pricebook2Id)) {
        Opportunity oppn = new Opportunity(id = op.Id, Pricebook2Id= op.Pricebook2Id);
        oppn.IncentiveSlab__c = incMap.get(oppn.Pricebook2Id);
        OppListtoUpdate.add(oppn);
        
        }
    }
    
    if(OppListtoUpdate.size() > 0)
    {
    Update OppListtoUpdate;    
    IFlag=True;
    }
    
    
    IF(IFlag==True)
    {
        
         for(Opportunity opp : opplist)
        {            
                Project__C Pro =New project__C();
                Pro=[select ID, Date_of_Installation__c from Project__C where ID=:ProjectiD];
                if (Pro.Date_of_Installation__c != null) {
                
                      NofoDays= Pro.Date_of_Installation__c .daysBetween(pDate);
                    }
           
        
        
    inc =[select ID from Incentive__c where ID =:Opp.IncentiveSlab__c
     and Opp_Discount_To__c>=:opp.Discount__c ];
    
    
    If(inc.size()>0 && Opp.Customer_Slab_Type__c!='Type 4')
    {   
    
   lstIli = [select id,Other_Mode__c,Neft_Cash__c, Payment_Term_From_Days__c, Payment_Term_To_Days__c 
            from IncentiveLineItem__c where Incentive__c = : opp.IncentiveSlab__c and 
            Payment_Term_To_Days__c >=: NofoDays and 
            Customer_Mode__c=:opp.Customer_Slab_Type__c];
            
     } 
     Else IF(inc.size()>0 && Opp.Customer_Slab_Type__c=='Type 4')
        {
        
             Payment__c  PMT =new Payment__c  ();
            
             PMt=[select ID,Date__c,Advance_Payment__c,Payment_Type__c from Payment__c  where Project__c=:ProjectiD
             and Payment_Type__c='Advance' and ID!=:PAYID];
         
             IF(PMT.Advance_Payment__c!=Null)
             {
               
                lstIli = [select id,Other_Mode__c,Neft_Cash__c, Payment_Term_From_Days__c, Payment_Term_To_Days__c 
                from IncentiveLineItem__c where Incentive__c = : opp.IncentiveSlab__c and 
                Payment_Term_To_Days__c >=: NofoDays and 
                Discount_To__c>=:PMT.Advance_Payment__c and Discount_From__c>=:PMT.Advance_Payment__c and
                Customer_Mode__c=:opp.Customer_Slab_Type__c];
               
             }
         
         }
     

    if (lstIli.size() > 0) { 
   
        
      if (PType.contains('Cash') || PType.contains('NEFT'))
            opp.NewIncentivePercentage__c = lstIli[0].Neft_Cash__c;
        else if (PType.contains('Others'))
             opp.NewIncentivePercentage__c = lstIli[0].Other_Mode__c;
       else
            opp.NewIncentivePercentage__c =0;
        list<Opportunity> lstOpp = new list<Opportunity>();
        lstOpp.add(opp);
        update lstOpp;
    }
    
    
    
    
             
     }
             
      }
 }
Hi All,

I wrote a trigger to update Incentive slab in Opportunities.But its, not updating.

kindly Let me know where am doing mistake:

trigger Incentive_Slot on Payment__c (after insert, after update) {
    
    Id OppId;
    ID ProjectID;
    Id IncId;
    Date pDate;
    Opportunity opp = new Opportunity();
     
    
    list<IncentiveLineItem__c> lstIli = new list<IncentiveLineItem__c>();
  
    
    for(Payment__c pRow: Trigger.new) {
        if( (prow.Payment_Type__c == 'Full Pay') || (prow.Payment_Type__c == 'Final Pay')) {
            OppId = prow.Opportunity__c;
             ProjectID = prow.Project__c;
            pDate = prow.Date__c;
        } 
    }
    
    if(OppId!=NUll || OppId!='')
    {    
  
    opp = [select id, Discount__c,StageName, Work_Order_Date__c, Date__c, Pricebook2Id, Pricebook_Name__c, 
            IncentiveSlab__c, Last_Payment_Received_Date__c, Incentive_For__c, Incentive__c,
            NewIncentivePercentage__c, IncentiveLast_Payment_Date__c, Final_Full_Payment_Date__c, 
            Outstanding_Amount__c, Special_Incentive_Account__c from Opportunity where id =: oppId]; 
    
    
    if (opp.StageName=='Closed Won' && opp.ID!=Null) {
        Incentive__c inc = new Incentive__c();        
            
            inc = [select Id from Incentive__c where Price_Book__c=: opp.Pricebook_Name__c and Active__c = true ];

                  
                opp.IncentiveSlab__c = inc.Id;
                Update Opp;   
        
   
       
                }
                
    
    }
    
}
 
Hi All,

I wrote a Test class for trigger but  my test class not given the code covereage:
My Trigger:

trigger RolluplineitemTrigger on QuoteLineItem  (after insert, after update) {
if(CheckRecurisive.runOnce()){
    List<Id> VQuoteID = new List<Id>();
    
    for(QuoteLineItem p: Trigger.new) {
        VQuoteID.add(p.QuoteiD);
    }
    
    AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
    WHERE QuoteiD in :VQuoteID  GROUP BY QuoteiD];
    
    Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c 
    FROM Quote WHERE Id in :VQuoteID]); 
    
    for(AggregateResult ar: groupedResults) {
    
    QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');

       
    }
    
  
        update QuoteMap.values();
  

}

}


test Class;
@isTest(seealldata=true)
Public class v2_QuoteLineItemTaxUpdate_Test{
    static testMethod void Testv2_QLITaxUpdate(){
        
        GetInitialData Getdata = new GetInitialData();
        list<Account> acc = Getdata.getAccount();
        list<Product2> lstprod = Getdata.getProd();
        list<Opportunity> Opp = Getdata.getOpp();
        list<Pricebook2> lstPB = Getdata.getpricebook();
        list<Pricebookentry> lststdPbe = Getdata.getstdpbe();
        list<Pricebookentry> lstPbentry = new list<Pricebookentry>();
        insert lstprod; 
        
        Integer indexvalue = 0;
        if(lstprod.size()>0)
        {
            for(pricebookentry irow :lststdPbe)
            {
                irow.product2id = lstprod[indexvalue].id;
                
                indexvalue++;
            }
        }
        
        
        insert lststdPbe;
        
        insert lstPB; 
        
        
        if(lstprod.size()>0)
        {
            for(pricebook2 irow :lstPB)
            {
                for(Product2 ipro : lstprod ){
                    Pricebookentry pbe = new Pricebookentry();
                    pbe.product2id = ipro.id;
                    pbe.pricebook2id = irow.id;
                    pbe.unitprice = 3000;
                    pbe.isActive = true;
                    lstPbentry.add(pbe);
                }
            }
        }

        insert lstPbentry;
        insert acc[0];
        
        Opp[0].accountId = acc[0].id;
        insert Opp[0]; 
        
        Opp[0].Pricebook2Id = lstPB[0].id;
        update Opp[0];
        
        OpportunityLineItem OL = new OpportunityLineItem(opportunityid=Opp[0].id, Quantity=1, unitprice=8000,  
            pricebookentryid=lstPbentry[0].id);
        insert OL; 
        
        Tax_Master__c   txm= new Tax_Master__c(CGST__c=14.00,HSN_Code__c=lstprod[0].HSN_Code__c,IGST__c=28.00,SGST__c=14.00, Start_Date__c =  Date.newInstance(2017, 07, 06), End_Date__c = System.today()+2);
        insert txm;  
            
        Quote Q = new Quote();
        Q.Name = 'QuoteOrbit';
        Q.OpportunityId = Opp[0].id; 
        Q.Quote_Count__c = 00000000;
        Q.Quote_Number__c ='000000';
        Q.Approved__c = false;
        Q.Quotation_Date__c = date.newinstance(2013,3,5);
        Q.Pricebook2Id = lstPB[0].id;
        Q.Tax_Classification__c='IGST';
        Q.Discount_Amount__c = 100;
        
        insert Q;  
        
          Q.Tax_Classification__c='IGST';
          Q.Discount_Amount__c = 100; 
          update Q ;       
        
        
      
       
        
        Quotelineitem QL = new Quotelineitem(quoteId=Q.id,SGST__c=6, CGST__c=6,IGST__c =0,Quantity =1, Unitprice=8000,pricebookentryid=lstPbentry[0].id);
           insert QL; 
        
           Opp[0].SyncedQuoteId = Q.id;
           update Opp[0];
           
            Q.Approved__c = true;   
          Update Q;
          
          Q.Approved__c = true;           
           update Opp[0];
        
        
          QuoteLineitem qli = [Select Id From QuoteLineItem where quoteId=:Q.id limit 1]; 
          Q.Tax_Classification__c='IGST';
          qli.SGST__c =6;
          QLI.CGST__c=6;
          QLI.IGST__c =0;          
           
          
           
        
                
         
         
           
               
       
         Quote Q1 = new Quote();
        Q1 .Name = 'QuoteOrbit';
        Q1 .OpportunityId = Opp[0].id; 
        Q1 .Quote_Count__c = 00000000;
        Q1 .Quote_Number__c ='000000';
        Q1 .Approved__c = false;
        Q1 .Quotation_Date__c = date.newinstance(2013,3,5);
        Q1 .Pricebook2Id = lstPB[0].id;
        Q1 .Tax_Classification__c='IGST';
        Q1 .Discount_Amount__c = 100;
        insert Q1;
          
        
         Utils u = new Utils();
        Long val = 100000000;
        u.convert(val);
        
         
         
        Test.startTest();
           
    
     
     AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
     GROUP BY QuoteiD limit 1];
     
     decimal Stock;
     
      for(AggregateResult res:groupedResults ){ 
      Stock=(Decimal)groupedResults [0].get('lineItemCOunt');         
                
        }    
       
      CheckRecurisive.runOnce();      
      update qli;  

        Test.stopTest(); 
        
      
    }
    }


 
Hi All,
I have two triggers in quote and Quote line item
Quote Trigger; v2_QuoteTaxUpdate
Quote line Item Trigger: RolluplineitemTrigger

while testing the RolluplineitemTrigger in QuotelineItem am  getting the following error

User-added image

kindly Let me know where am doing mistake
RolluplineitemTrigger;

trigger RolluplineitemTrigger on QuoteLineItem  (after insert, after update) {

    List<Id> VQuoteID = new List<Id>();
    
    for(QuoteLineItem p: Trigger.new) {
        VQuoteID.add(p.QuoteiD);
    }
    
    AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
    WHERE QuoteiD in :VQuoteID  GROUP BY QuoteiD];
    
    Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c 
    FROM Quote WHERE Id in :VQuoteID]); 
    
    for(AggregateResult ar: groupedResults) {
    
    QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');

       
    }
    
    //try {
        update QuoteMap.values();
    //}   catch(DmlException e) {
        //System.debug(e.getMessage());
    //}

}

v2_QuoteTaxUpdate:

trigger v2_QuoteTaxUpdate on Quote (after insert, after update) {

    list<QuoteLineItem> lstUpdateQLI = new list<QuoteLineItem>();
    set<id> setQuoteId = new set<id>();
     set<id> setQuoteIdTaxUpd = new set<id>();
    set<id> setQLIId = new set<id>();
    set<String> setHSNCode = new set<String>();  
    List<Id> VQuoteID = new List<Id>();  
    map<string, list<Tax_Master__c>>mapTaxMasToTaxKey = new map<string, list<Tax_Master__c>>();    
        
    for(Quote iQLI : Trigger.New){   
        If(Trigger.Isinsert) {
        
            if(iQLI.Tax_Classification__c !=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
                
            }
        }
        
        if(Trigger.isupdate) {
        
         if(iQLI.Tax_Classification__c!=''){
            
                setQuoteId.add(iQLI.id);
                setQuoteIdTaxUpd.add(iQLI.id);
                system.debug('****setQLIId'+setQLIId);       
          }            
          if(iQLI.Discount_Amount__c!=Null){  
          
              setQuoteId.add(iQLI.id);
              system.debug('****setQLIId'+setQLIId);  
          }
        
        }
        
    }
    
        
    
    if(setQuoteId.size() > 0){
    
        for(Quote iQuot : [SELECT id,(SELECT id, Product2.HSN_Code__c FROM QuoteLineItems ) 
            FROM Quote WHERE Id IN :setQuoteIdTaxUpd]){
        
            for(QuoteLineItem iQLI : iQuot.QuoteLineItems){
                  
                    if(iQLI.Product2.HSN_Code__c != ''){
                    
                        setHSNCode.add(iQLI.Product2.HSN_Code__c);
                    }    
            }   
            system.debug('****setHSNCode'+setHSNCode);                    
        }
        
        if(setHSNCode.size() > 0){
        
            if(setHSNCode.size() > 0){
            
                for(Tax_Master__c iTM : [SELECT id, Product_Family__c,Product_Sub_Family__c,HSN_Code__c, IGST__c, CGST__c, SGST__c, Active__c,Start_Date__c,End_date__c FROM Tax_Master__c  WHERE HSN_Code__c IN :setHSNCode ]){
                
                     String ikey = iTM.HSN_Code__c;
                    if(!String.isblank(iTM.Product_Family__c))
                    {
                        ikey = ikey + iTM.Product_Family__c;                         
                    } 
                    if(!String.isblank(iTM.Product_Sub_Family__c))
                    {
                        ikey = ikey + iTM.Product_Sub_Family__c;                         
                    } 
                    list<Tax_Master__c> lstTax = new list<Tax_Master__c>();
                    lstTax.add(iTM);
                    if(mapTaxMasToTaxKey.containskey(ikey))
                    {
                        lstTax.addall(mapTaxMasToTaxKey.get(ikey));
                    }
                    mapTaxMasToTaxKey.put(ikey, lstTax); 
                                 
                 }   
                    system.debug('****mapTaxMasToTaxKey'+mapTaxMasToTaxKey);                    
 
            }  
            
                  
            
            for(Quote iQuot : [SELECT id, Tax_Classification__c, Discount_Amount__c,Anki_total_Amt__c,
                (SELECT CreatedDate,Product2.family, Product2.Sub_Family__c,Product2.HSN_Code__c, Tax_Master__c, IGST__c, CGST__c, SGST__c FROM QuoteLineItems) 
                FROM Quote WHERE Id IN :setQuoteId]){
            
                for(QuoteLineItem iQLI : iQuot.QuoteLineItems){  
                       
                       system.debug('****iQuot.Discount_Amount__c'+iQuot.Discount_Amount__c); 
                       system.debug('****iQuot.Anki_total_Amt__c'+iQuot.Anki_total_Amt__c); 
                          
                          if(iQuot.Discount_Amount__c <= 0 ){
                                iQLI.Q_Discount__c = 0;    
                          
                            } else {
                                if(iQuot.Discount_Amount__c != null && iQuot.Anki_total_Amt__c !=null){
                                iQLI.Q_Discount__c =(iQuot.Discount_Amount__c/iQuot.Anki_total_Amt__c) * 100;
                                
                                }
                            } 
                                                       
                         system.debug('****Q_Discount__c'+iQLI.Q_Discount__c);
                        Date myDate =  date.parse('11/10/2017');
                        Date myDate2 = date.parse(iqli.CreatedDate.day()+'/'+iqli.CreatedDate.month()+'/'+iqli.CreatedDate.year());
                        
                        Tax_Master__c itax = new Tax_Master__c();
                        
                        
                        if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c) && myDate2 >= myDate ){
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family+iQLI.Product2.Sub_Family__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family) && myDate2 >= myDate ){
                            
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c+iQLI.Product2.Family))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }else if(mapTaxMasToTaxKey.containsKey(iQLI.Product2.HSN_Code__c))
                        {
                            for(Tax_Master__c irow : mapTaxMasToTaxKey.get(iQLI.Product2.HSN_Code__c))
                            {
                                if(irow.Start_Date__c <= iqli.CreatedDate && irow.End_Date__c  >= iqli.CreatedDate)
                                {
                                
                                    itax = irow;
                                    break;
                                }
                            }
                        }
                        
                        if(!String.isblank(itax.id)){
                    
                        iQLI.Tax_Master__c = itax.id;
                        
                        
                        
                        if(iQuot.Tax_Classification__c == 'IGST'){
                        
                            iQLI.IGST__c = itax.IGST__c;
                            iQLI.SGST__c = 0; 
                            iQLI.CGST__c = 0;
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;
                        } 
                        
                        if(iQuot.Tax_Classification__c == NUll){
                        
                            iQLI.SGST__c = 0;
                            iQLI.CGST__c = 0;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }
                        if(iQuot.Tax_Classification__c == 'SGST'){
                        
                            iQLI.SGST__c = itax.SGST__c;
                            iQLI.CGST__c = itax.CGST__c;    
                            iQLI.IGST__c = 0;  
                            //iQLI.Q_Discount__c = iQuot.Ankidyne_Discount_Percentage__c;                      
                        }                       
                        
                        lstUpdateQLI.add(iQLI);                            
                    }    
                                         
                }    
            }  
            
            if(lstUpdateQLI.size() > 0){            
                update lstUpdateQLI;
            }          
        }
    }
}

 
Hi All,
I have the Qline Item With Cross object Formula Field (Stock_Not_Available__c)     

I want to rollup this field in quote object( No_of_Products_Stock_Not_Available__c)



My trigger Working working for add. Sum() Exam- 5
But if the count is  reduced in Quote line item it's not revert backing in Quote  Emaple 2

Result remain same in Quote as Exam; 5

I wrote  a trigger   :

trigger RollupProjectCountTrigger on QuoteLineItem  (Before Insert, after insert) {

    List<Id> VQuoteID = new List<Id>();
    
    for(QuoteLineItem p: Trigger.new) {
        VQuoteID.add(p.QuoteiD);
    }
    
    AggregateResult[] groupedResults = [SELECT Sum(Stock_Not_Available__c) lineItemCOunt, QuoteiD FROM QuoteLineItem 
    WHERE QuoteiD in :VQuoteID  GROUP BY QuoteiD];
    
    Map<id,Quote> QuoteMap = new Map<Id,Quote>([SELECT id, No_of_Products_Stock_Not_Available__c 
    FROM Quote WHERE Id in :VQuoteID]); 
    
    for(AggregateResult ar: groupedResults) {
    
    QuoteMap.get((Id)ar.get('QuoteiD')).No_of_Products_Stock_Not_Available__c = (decimal) ar.get('lineItemCOunt');

       
    }
    
    try {
        update QuoteMap.values();
    }   catch(DmlException e) {
        System.debug(e.getMessage());
    }

}


Kindly let me know where am doing mistake