• Neeraj Sharma 103
  • NEWBIE
  • 220 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 30
    Replies
Hi Everyone Please Help me 

How to Create Registration Visual force Page for community user anyone create so please help me any example 
Trigger

trigger LeadTrigger on Lead(before insert, before Update) {

    if (trigger.isInsert && trigger.isBefore) {
        LeadTriggerHandler.onBeforeInsert(trigger.new);

    } else if (trigger.isUpdate && trigger.isBefore) {
        LeadTriggerHandler.onBeforeUpdate(trigger.new, trigger.oldMap);
    }
}
 
TrigerHandlerClass

public class LeadTriggerHandler {
  
    public static String STATUS_SELF_REPRESENTED = 'Self Represented';
    
  
    public static void onBeforeInsert(list <Lead> newLeadList){
        updateFldsOnLead(newLeadList, null);
    }

   
    public static void onBeforeUpdate(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){
        updateFldsOnLead(newLeadList, oldLeadMap);
    }

    public static void updateFldsOnLead(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){
        map<String, list<lead>> zipCodeLeadMap = new Map <String, list<lead>> ();

       for(Lead ld: newLeadList){
            if(ld.Status != STATUS_SELF_REPRESENTED && ld.PostalCode != null){
              
               
                if(!zipCodeLeadMap.containsKey(ld.PostalCode)){
                    zipCodeLeadMap.put(ld.PostalCode, new list<lead>());
                }
                zipCodeLeadMap.get(ld.PostalCode).add(ld);
            }

        }
        if(zipCodeLeadMap.size() > 0){
           
            for(Lead_WF_Configuration__mdt ldConfigCMD: [Select Id, Zip_Postal__c, State__c, County__c,OwnerID__c
                                                          From Lead_WF_Configuration__mdt]){
                                                
                for(String zip: zipCodeLeadMap.keySet()){
                    
                    if(String.valueOf(ldConfigCMD.Zip_Postal__c).contains(zip)){
                        
                        
                        for(Lead ld: zipCodeLeadMap.get(zip)){
                            ld.State = ldConfigCMD.State__c;
                            ld.County__c = ldConfigCMD.County__c;
                            ld.OwnerId = ldConfigCMD.OwnerID__c;
                        }
                 }
                 }
            }
        }
    }
}

 
Hi Experts

Hi Everyone When i used Bootstrap 4 in visualforce page then the tag color will be different how its is possbile and developer console is not showing any errorUser-added image
Hi Experts i have a Simple vf page and in vf page some fields are input and a save button when user fill the form and then clicked on save button then the data will be stored as a pdf and download it 
So Any Example how to achieve this functionaliy 
Hi Please help for test class

public with sharing class schedulexpensecontroller {

     public list<Expense_Management__c> con{get;set;}  
     public list<Expense_Management__c> em{get;set;}  
     public double total1{get;set;} 
     public Date fromdate{get;set;}
     public Date todate{get;set;}
     
	 public Id parent {get;set;} 
    
     public schedulexpensecontroller(){
    	
        
  	    Id conId = apexpages.currentpage().getparameters().get('id');
        parent = UserInfo.getUserId();
         
 			
                     
          
        if(apexpages.currentpage().getparameters().get('fromdate') !=null && apexpages.currentpage().getparameters().get('todate')!=null)
        {
             fromdate = Date.Parse(apexpages.currentpage().getparameters().get('fromdate'));
             todate = Date.Parse(apexpages.currentpage().getparameters().get('todate'));
            
            con = [Select Date__c,From__c,To__c,Purpose_of_Travel__c,Mode_of_Travel__c,
                  Opening_KM__c,Closing_KM__c,Rate__c,Total_Km__c,Total_Travel_Expense__c	,
                  Lodging_Expense__c,Miscellaneous_Expense__c,
                  Description__c,Total_Expenses__c,Local_Conveyance__c,	Paid_Amount__c,Payment__c,
                  Name_of_Employee__r.EmployeeNumber,Name_of_Employee__r.UserRole.Name,Name_of_Employee__r.Name from Expense_Management__c
                  where Name_of_Employee__c =: parent AND CreatedDate >=: fromdate AND CreatedDate <=: todate];
            
            em = [Select Payment__c,Total_Expenses__c from Expense_Management__c where Payment__c = 'unpaid' AND Name_of_Employee__c =: parent];  
        }else
        {
            
              con = [Select Date__c,From__c,To__c,Purpose_of_Travel__c,Mode_of_Travel__c,
                  Opening_KM__c,Closing_KM__c,Rate__c,Total_Km__c,Total_Travel_Expense__c	,
                  Lodging_Expense__c,Miscellaneous_Expense__c,
                  Description__c,Total_Expenses__c,Local_Conveyance__c,	Paid_Amount__c,Payment__c,
                  Name_of_Employee__r.EmployeeNumber,Name_of_Employee__r.UserRole.Name,Name_of_Employee__r.Name from Expense_Management__c
                  where Name_of_Employee__c =: conId ];
            
              em = [Select Payment__c,Total_Expenses__c from Expense_Management__c where Payment__c = 'unpaid' AND Name_of_Employee__c =: conId];
        }
        
    }
}
@isTest
public class Testclassforscheduleexpensecontroller {

    @isTest static void testmethod1()
    {
        schedulexpensecontroller cons= new schedulexpensecontroller();
          // Date from1;
      // cons.fromdate=from1.parse('06/18/2019');
        
       
       //fromdate = Date.Parse(apexpages.currentpage().getparameters().get('fromdate'));
    }
}


 
public class EmailInvoiceA {
    
    @auraEnabled
    public static void sendMailWithPDF(String recordId){
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           sendTo.add(cc.Distributor__r.E_mail__c);
            
            List<String> send = new List<String>();
            if(cc.Distributor__r.E_mail__c==null && cc.Distributor__r.CC_to_if_any__c != null)
            {  
                send.add(cc.Distributor__r.CC_to_if_any__c);
               semail.setToAddresses(send);
            }
            else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c != null)
            {
                sendTo.add(cc.Distributor__r.E_mail__c);
                send.add(cc.Distributor__r.CC_to_if_any__c);
              semail.setccAddresses(send);
              semail.setToAddresses(sendTo);
                
           }
           else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c == null)
            {  
              sendTo.add(cc.Distributor__r.E_mail__c);
                   semail.setToAddresses(sendTo);
         }
                mails.add(semail);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
        }
    }      
    @auraEnabled
     public static void sendMailWith(String recordId,String mMail){
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            sendTo.add(mMail);
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           
           
              List<String> send = new List<String>();
            if(cc.Distributor__r.CC_to_if_any__c != null)
            {
                 send.add(cc.Distributor__r.CC_to_if_any__c);
                 
            }
            mails.add(semail);
			semail.setCcAddresses(send);
            semail.setToAddresses(sendTo);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
        }
    }    
     @auraEnabled
   public static void Mail(String recordId,String mMail,boolean checkCmp){
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();        
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
  
           if(checkCmp==true)
               {
                  sendTo.add(mMail);
                   semail.setToAddresses(sendTo);
               }
           else  if(checkCmp==false)
            {
              if(mMail != null)
            {
                sendTo.add(mMail);
            	semail.setToAddresses(sendTo);
            }   
             if(cc.Distributor__r.E_mail__c != null)
            {
               sendTo.add(cc.Distributor__r.E_mail__c);  
                semail.setToAddresses(sendTo);
            } 
                
             if(cc.Distributor__r.CC_to_if_any__c != null)
            { 
                List<String> send = new List<String>();//cc string
				send.add(cc.Distributor__r.CC_to_if_any__c);  
               semail.setCcAddresses(send);
           }   
            }
            mails.add(semail);

            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
        }
    }       
}

 
Hi Experts 

Can we create a salesforce bell notification for approval process using Apex Trigger,Apex class , Lightning Component  I searched on google also its says By Using Process builder we create a salesforce custom notification but i want to send notification when user clicked on the submit for approval button i am and in approval process My Users in queues so salesforce not sent bell notification to Queue Users so how to send bell notificatio Queue Users If any one doing this type of scenario so please share with me Any Example 


Thanks in Advance
Neeraj Sharma
Hi Experts Please Help me For Below Code

in this code i used lightning data table it show not proper in salesforce1 mobile app its shows like this:User-added image
<aura:component implements="force:LightningQuickAction,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="Eventrecordcomponent">
  
    <!-- attributes -->
    <aura:attribute name="recordId" type="String"></aura:attribute>
     <aura:attribute name="recordTypes" type="String"></aura:attribute>
    <aura:attribute name="mydata" type="Object"></aura:attribute>
    <aura:attribute name="mycolumns" type="List"></aura:attribute>
    <aura:attribute name="noResults" type="String"></aura:attribute>
   
    <!-- handlers-->
    <aura:handler name="init" value="{!this }" action="{!c.init }"></aura:handler>
   <article aura:id="gridContainer" class="slds-card slds-card_boundary">
        <lightning:card title="Check In/Check Out Manager" iconName="standard:document">
            <div class="slds-card__header slds-grid">
                <aura:if isTrue="{!not(empty(v.mydata))}" >
                    <!-- the container element determine the height of the datatable -->
                    <lightning:datatable keyField="id"
                            data="{! v.mydata }"
                            columns="{! v.mycolumns }"
                            hideCheckboxColumn="true"
                         
                         ></lightning:datatable>
                </aura:if>
                <aura:if isTrue="{!empty(v.mydata)}" >
                    <p Style="color:red;">{! v.noResults }</p>
                  
                </aura:if>
            </div>
        </lightning:card>
    </article>
</aura:component>

So Please Replay ASAP 
Thanks in Advance
Neeraj
Hi  
Everyone How to calculate distance between two marker and show them on the Map like CheckIn and CheckOut when user check in then its show on the map i doing this already now i want to show checkout also on the map and also distance calculate between them and  distance show on the checkin marker 

Please Replay ASAP 
Thanks in Advance
Neeraj
Please Help me to write test class for below apex class controller


abc.apexclass


public class EmailInvoiceA {
    
    @auraEnabled
    public static void sendMailWithPDF(String recordId){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();//to string
        
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           
           sendTo.add(cc.Distributor__r.E_mail__c);
            
            List<String> send = new List<String>();//cc string
            system.debug('sendlis'+send);
        //    if(cc.Distributor__r.CC_to_if_any__c != null)
      //      {
        //         send.add(cc.Distributor__r.CC_to_if_any__c);
                 
     //       }
            
            if(cc.Distributor__r.E_mail__c==null && cc.Distributor__r.CC_to_if_any__c != null)
            {  
                
                send.add(cc.Distributor__r.CC_to_if_any__c);
               //semail.setccAddresses(sendTo);
               semail.setToAddresses(send);
           
            }
            else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c != null)
            {
                sendTo.add(cc.Distributor__r.E_mail__c);
                send.add(cc.Distributor__r.CC_to_if_any__c);
                
              semail.setccAddresses(send);
              semail.setToAddresses(sendTo);
                
           }
           else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c == null)
            {
                
              sendTo.add(cc.Distributor__r.E_mail__c);
               
                   semail.setToAddresses(sendTo);
         }
       
        
                mails.add(semail);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
        }
    }    
  
    
    @auraEnabled
     public static void sendMailWith(String recordId,String mMail){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            sendTo.add(mMail);
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           
            //sendTo.add(cc.Distributor__r.E_mail__c);
              List<String> send = new List<String>();
            if(cc.Distributor__r.CC_to_if_any__c != null)
            {
                 send.add(cc.Distributor__r.CC_to_if_any__c);
                 
            }
         
            mails.add(semail);
            semail.setCcAddresses(send);
            semail.setToAddresses(sendTo);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
            system.debug('email send');
        }
    }    
  
    
     @auraEnabled
   public static void Mail(String recordId,String mMail,boolean checkCmp){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();//to string
           
              system.debug(checkCmp);  
           
       //     semail.setToAddresses(sendTo);
          //shrutinigam1998@gmail.com  
        
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
            
            
            
           if(checkCmp==true)
               {
                  sendTo.add(mMail);
                   semail.setToAddresses(sendTo);
               }
           else  if(checkCmp==false)
            {
               system.debug('hi check'+checkCmp);
              if(mMail != null)
            {
                 system.debug('hi mMail'+mMail);
                sendTo.add(mMail);
                semail.setToAddresses(sendTo);
            }
                
             if(cc.Distributor__r.E_mail__c != null)
            { system.debug('hi Distributor mail'+cc.Distributor__r.E_mail__c);
               sendTo.add(cc.Distributor__r.E_mail__c);  
                semail.setToAddresses(sendTo);
            } 
                
             if(cc.Distributor__r.CC_to_if_any__c != null)
   
            { 
                system.debug('hi Distributor cc mail'+cc.Distributor__r.CC_to_if_any__c);
                List<String> send = new List<String>();//cc string
                send.add(cc.Distributor__r.CC_to_if_any__c);  
               semail.setCcAddresses(send);
           }   
                
                
                
            }
            
      
            mails.add(semail);

            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
            system.debug('email send');
        }
    }       
}
HI all,
I habve created a quick lightning action button and in the pop up i have placed one checkbox.

Problrm is that when condition is false it is working perfectly when it is true it is not calling the aura enabled class in controller.

 
Hi Everyone this is my trigger i want to write test class for this so please help me i tried but not accomplish my requirement code coverge approx 75%



trigger Distributor on Account (before insert) {
    
String role;   
String owner;
    
  list<Account> changeOwner=new list<Account>();
    
    for(Account acc:trigger.new){
        
       if(acc.Under__c=='Chhattisgarh'){
           role=' CG';
          changeOwner.add(acc);
       }
      
       else if(acc.Under__c=='Bihar'){
           role=' BI';
         changeOwner.add(acc);
       }  
        
      else if(acc.Under__c=='Rajasthan') {
           role=' RJ';
           changeOwner.add(acc);
           }  
      else if(acc.Under__c=='Gujarat'){
           role=' GJ';
          changeOwner.add(acc);
           }
        
      else if(acc.Under__c=='Haryana'){
           role=' HR';
         changeOwner.add(acc);
           
       }
        
      else if(acc.Under__c=='Jharkhand'){
           role=' JH';
         changeOwner.add(acc);
       } 
        
      else if(acc.Under__c=='Maharashtra'){
           role=' MH';
         changeOwner.add(acc);
       }
        
       else if(acc.Under__c=='Madhya Pradesh'){
           role=' MP';
         changeOwner.add(acc);
       }  
       else if(acc.Under__c=='Uttar Pradesh'){
           role=' UP';
        changeOwner.add(acc);
       } 
        
   }
    String SOSTR = String.valueOf('SO') + String.valueOf(role);  
    String ASMSTR = String.valueOf('ASM') + String.valueOf(role);
    String DRMSTR = String.valueOf('DRM') + String.valueOf(role);
    String RMSTR = String.valueOf('RM') + String.valueOf(role);


  list <User> socg1=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :SOSTR Order By FirstName,LastName');
  list <User> socg2=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :ASMSTR Order By FirstName,LastName');
  list <User> socg3=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :DRMSTR  Order By FirstName,LastName');
  list <User> socg4=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :RMSTR Order By FirstName,LastName');
  
   if(socg1.size()>0){
        owner=socg1.get(0).id;
    }
    
     else if(socg1.size()<=0){
     
        if(socg2.size()>0){
            owner=socg2.get(0).id; 
        }
        
        else if(socg2.size()<=0){
            
            if(socg3.size()>0){
              owner=socg2.get(0).id;  
             }
        
        else if(socg3.size()<=0){
            
             if(socg4.size()>0) {
               owner=socg4.get(0).id;   
             }   
        }
      }
   }
    
   for(Account acc:changeOwner){
       
        if(socg1!=null){
            acc.OwnerId=Owner;
        }
           
    }
   
}
Hi Everyone how to reduce line of codes 
this logic i used many times in trigger and my code length is line 400 lines so how to reduce them only the UserRole.Name is changed according to hierarchy because my hierarchy is so long its for 6-7 states so i used this logic for all states only role name is changed in the query this below code part is only little






trigger Distributor on Account (before insert,before update) {
    
String role;
String owner;
    
  list<Account> changeOwner=new list<Account>();
    
    for(Account acc:trigger.new){
        
       if(acc.Under__c=='Chhattisgarh'){
           role='SO CG';
           changeOwner.add(acc);
       }
   list <User> socg1=[select id,Name from User where UserRole.Name='SO CG' Order BY FirstName,LastName];
   list <User> socg2=[select id,Name from User where UserRole.Name='ASM CG' Order BY FirstName,LastName];
   list <User> socg3=[select id,Name from User where UserRole.Name='DRM CG' Order BY FirstName,LastName];
   list <User> socg4=[select id,Name from User where UserRole.Name='RM CG' Order BY FirstName,LastName];
  
   if(socg1.size()>0){
        owner=socg1.get(0).id;
    }
    
     else if(socg1.size()<=0){
     
        if(socg2.size()>0){
            owner=socg2.get(0).id; 
        }
        
        else if(socg2.size()<=0){
            
            if(socg3.size()>0){
              owner=socg2.get(0).id;  
             }
        
        else if(socg3.size()<=0){
            
             if(socg4.size()>0) {
               owner=socg4.get(0).id;   
             }   
        }
      }
   }
   for(Account acc:changeOwner){
       
        if(socg1!=null){
            acc.OwnerId=Owner;
        }
    }
    

Hi Everyone Please help me out from this scenario

 I want to update Account record owner incase custom state field is anyone selected from picklist(Gujarat,Rajasthan,Bihar,etc) with higher role and role checked 

User-added image
four levels above in role hiearchy if state chandigarh is select then (SOCG (SalesOfficer Chandigarh)) in this role the user will be updated on record owner and if no user in role of (SOCG) then above him(ASM CG) user is update on record owner this level go up to last level at (RM CG) 
and if RMCG in this role there is no user then by default  record owner will be update to this role user(RM CG)
 
Hi Everyone I am new in Salesforce/Beginner
My Scenario is:

If a Account record is created and custom state field(Picklist)  value is Gujarat then owner should be changed with some role in hierachy i want to check four levels for assigned a new user to existing account owner if last role is not available then user above him role hierarchy will be assigned and if above them is not availble then above him is assigned so this levels up to four level and last one by default assigned below all are not available

 
Hi  Everyone
I am beginner in salesforce so i am facing a issue in this scenario
So Please Help me out for this Scenario How to Do this?

When User Opens the records by default current user's should be selected in 'Name of the Employee ' Field is on Visualforce Page and One Custom Object and in Custom Object when i clicked a new button for a record then the visualforce page is opened so the field is created in Visualforce Page with name Name of the Employee and this field fetch the all users records so i want when a user login with our credentials and go to the Custom object and create a new record then the Name of the Employee field is auto populated with login Users name in Name of the Employee Field and this situation for all users.
i Everyone i am new in Salesforce 
So Please Help Me Out From this Scenario 

I have a two Custom Field on a Custom Object
1.ZipCode(Text)   

   Api Name=Zip_Code__c

2.Owner(Lookup User)
 

  Api Name=Owner

On Territory(Territory__c) Custom Object


My Condition is When i Insert a Zip Code like example:
1.332713=Aaron(Owner)
2.332713=Blake(Owner)
3.332713=Denise(Owner)

When i again insert 332713 and assign to a new Owner then Display a error we can not Assign a zipcode to this user Only a single zipcode is assigned to only three Owners(Sales Representatives)
Three Sales Representatives at most can be assigned to a single zipcode.Display an error if a user attempts to associate another sales representative to a zipcode

Please Replay As Soon Possible I dont know how to over come from this scenario so Please help me 

Thanks 
Neeraj Sharma
 
Hi Everyone 
I am New in Salesforce I am Beginner
So Please Help Me Out For this Scenario1
When an Account's BillingPostalCode is changed:
1.Change the Account Owner to the Sales Representative assigned to the new zip code

Sales Representative is in Another Object Territory(Territory__c)
in this object two Fileds one is ZipCode(Text) and other One is Owner(Lookup Field (User Lookup))
In First Requirement Change the Account Owner to the Owner Field in Territory and BillingPostalCode is also Mapp from ZipCode in territory Object and then Assign the AccountOwner to the Owner(Lookup) of Territory Object

2.Change the Owner field of all the Account’s Contacts to the same OwnerFiled in Territory Object(Sales Representative).

3.Change the Owner field of all the Account’s Open Opportunities to the same OwnerFiled in Territory Object(Sales Representative).


Please Replay as Soon Possible
How to use trigger i dont know about trigger So Please Help me out for this Scenario  this is my First Trigger to write So Please Help

Thanks in Advance       
Neeraj Sharma
 
Hi 
I am beginner in salesforce
So Please Help me out for this scenario
I have two Object one is Standard Object Account and other one is Terriotry object(Territory__c) 
So
i have create a custom field on territory object Zip Code(Text) 
Zip_Code__c  and Owner Lookup Field(User Lookup) Owner__c
when i create a new zip code and new Owner and then Save the Record

After that i am going on Account Object When i Create a new record and Update a Record and change the BillingPostalCode Field of Account then this Account Owner is Assigned to the New Owner that will be in Territory Object With Some New Zip Code and BillingPostal Code and Zip Code of Territory Object are compared and then Assign the new Owner to that Account to the Account Owner


So Please Help Me I am new in Salesforce i dont know how to write a trigger for this scenario This is My First Trigger So Plese Help Me
 
Hi  i am new in Salesforce
I am Beginner
So Please Help me Out from this Scenario

When an Account's Billing Zip/Postal Code field value is changed and entered new value then
this situation will occur
1.Change the Account Owner to the Sales Representative assigned to the new zip code(Sales Representative is users that will be in another custom Object Terriotry object its a lookup )
2.Change the Owner Field of all the Account's Contacts to the same Sales Representative
3.Change the Owner Field of all the Account's Open Opportunities to the Same Sales RepresentativeIn this Image this are the Sales Representative in Custom Object TerritoryIn this Image This are the Custom fileds of territory objectSo Please Help Me out From this Scenario How to Start From where i dont know 

Please Reply As Soon Possible

Thanks
Neeraj Sharma
Hi 

I am new in Salesforce Begineer

My Question is:

How to validate Phone field of Account Object with Use of Apex Class and the validation is ONly 10 Digit is input by user no sepcial character no characters Only digits and digit will be 10 
and if user input digit according the condition then the record will be save and user not input 10digit then error will be show on the Phone field "Please Provide Valid Number"  on Custom Visual force Page
Please help me ASAP


Thanks 
Neeraj Sharma
 
Trigger

trigger LeadTrigger on Lead(before insert, before Update) {

    if (trigger.isInsert && trigger.isBefore) {
        LeadTriggerHandler.onBeforeInsert(trigger.new);

    } else if (trigger.isUpdate && trigger.isBefore) {
        LeadTriggerHandler.onBeforeUpdate(trigger.new, trigger.oldMap);
    }
}
 
TrigerHandlerClass

public class LeadTriggerHandler {
  
    public static String STATUS_SELF_REPRESENTED = 'Self Represented';
    
  
    public static void onBeforeInsert(list <Lead> newLeadList){
        updateFldsOnLead(newLeadList, null);
    }

   
    public static void onBeforeUpdate(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){
        updateFldsOnLead(newLeadList, oldLeadMap);
    }

    public static void updateFldsOnLead(list <Lead> newLeadList, map <Id, Lead> oldLeadMap){
        map<String, list<lead>> zipCodeLeadMap = new Map <String, list<lead>> ();

       for(Lead ld: newLeadList){
            if(ld.Status != STATUS_SELF_REPRESENTED && ld.PostalCode != null){
              
               
                if(!zipCodeLeadMap.containsKey(ld.PostalCode)){
                    zipCodeLeadMap.put(ld.PostalCode, new list<lead>());
                }
                zipCodeLeadMap.get(ld.PostalCode).add(ld);
            }

        }
        if(zipCodeLeadMap.size() > 0){
           
            for(Lead_WF_Configuration__mdt ldConfigCMD: [Select Id, Zip_Postal__c, State__c, County__c,OwnerID__c
                                                          From Lead_WF_Configuration__mdt]){
                                                
                for(String zip: zipCodeLeadMap.keySet()){
                    
                    if(String.valueOf(ldConfigCMD.Zip_Postal__c).contains(zip)){
                        
                        
                        for(Lead ld: zipCodeLeadMap.get(zip)){
                            ld.State = ldConfigCMD.State__c;
                            ld.County__c = ldConfigCMD.County__c;
                            ld.OwnerId = ldConfigCMD.OwnerID__c;
                        }
                 }
                 }
            }
        }
    }
}

 
Hi Experts i have a Simple vf page and in vf page some fields are input and a save button when user fill the form and then clicked on save button then the data will be stored as a pdf and download it 
So Any Example how to achieve this functionaliy 
Hi Please help for test class

public with sharing class schedulexpensecontroller {

     public list<Expense_Management__c> con{get;set;}  
     public list<Expense_Management__c> em{get;set;}  
     public double total1{get;set;} 
     public Date fromdate{get;set;}
     public Date todate{get;set;}
     
	 public Id parent {get;set;} 
    
     public schedulexpensecontroller(){
    	
        
  	    Id conId = apexpages.currentpage().getparameters().get('id');
        parent = UserInfo.getUserId();
         
 			
                     
          
        if(apexpages.currentpage().getparameters().get('fromdate') !=null && apexpages.currentpage().getparameters().get('todate')!=null)
        {
             fromdate = Date.Parse(apexpages.currentpage().getparameters().get('fromdate'));
             todate = Date.Parse(apexpages.currentpage().getparameters().get('todate'));
            
            con = [Select Date__c,From__c,To__c,Purpose_of_Travel__c,Mode_of_Travel__c,
                  Opening_KM__c,Closing_KM__c,Rate__c,Total_Km__c,Total_Travel_Expense__c	,
                  Lodging_Expense__c,Miscellaneous_Expense__c,
                  Description__c,Total_Expenses__c,Local_Conveyance__c,	Paid_Amount__c,Payment__c,
                  Name_of_Employee__r.EmployeeNumber,Name_of_Employee__r.UserRole.Name,Name_of_Employee__r.Name from Expense_Management__c
                  where Name_of_Employee__c =: parent AND CreatedDate >=: fromdate AND CreatedDate <=: todate];
            
            em = [Select Payment__c,Total_Expenses__c from Expense_Management__c where Payment__c = 'unpaid' AND Name_of_Employee__c =: parent];  
        }else
        {
            
              con = [Select Date__c,From__c,To__c,Purpose_of_Travel__c,Mode_of_Travel__c,
                  Opening_KM__c,Closing_KM__c,Rate__c,Total_Km__c,Total_Travel_Expense__c	,
                  Lodging_Expense__c,Miscellaneous_Expense__c,
                  Description__c,Total_Expenses__c,Local_Conveyance__c,	Paid_Amount__c,Payment__c,
                  Name_of_Employee__r.EmployeeNumber,Name_of_Employee__r.UserRole.Name,Name_of_Employee__r.Name from Expense_Management__c
                  where Name_of_Employee__c =: conId ];
            
              em = [Select Payment__c,Total_Expenses__c from Expense_Management__c where Payment__c = 'unpaid' AND Name_of_Employee__c =: conId];
        }
        
    }
}
@isTest
public class Testclassforscheduleexpensecontroller {

    @isTest static void testmethod1()
    {
        schedulexpensecontroller cons= new schedulexpensecontroller();
          // Date from1;
      // cons.fromdate=from1.parse('06/18/2019');
        
       
       //fromdate = Date.Parse(apexpages.currentpage().getparameters().get('fromdate'));
    }
}


 
Hi Experts 

Can we create a salesforce bell notification for approval process using Apex Trigger,Apex class , Lightning Component  I searched on google also its says By Using Process builder we create a salesforce custom notification but i want to send notification when user clicked on the submit for approval button i am and in approval process My Users in queues so salesforce not sent bell notification to Queue Users so how to send bell notificatio Queue Users If any one doing this type of scenario so please share with me Any Example 


Thanks in Advance
Neeraj Sharma
Please Help me to write test class for below apex class controller


abc.apexclass


public class EmailInvoiceA {
    
    @auraEnabled
    public static void sendMailWithPDF(String recordId){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();//to string
        
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           
           sendTo.add(cc.Distributor__r.E_mail__c);
            
            List<String> send = new List<String>();//cc string
            system.debug('sendlis'+send);
        //    if(cc.Distributor__r.CC_to_if_any__c != null)
      //      {
        //         send.add(cc.Distributor__r.CC_to_if_any__c);
                 
     //       }
            
            if(cc.Distributor__r.E_mail__c==null && cc.Distributor__r.CC_to_if_any__c != null)
            {  
                
                send.add(cc.Distributor__r.CC_to_if_any__c);
               //semail.setccAddresses(sendTo);
               semail.setToAddresses(send);
           
            }
            else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c != null)
            {
                sendTo.add(cc.Distributor__r.E_mail__c);
                send.add(cc.Distributor__r.CC_to_if_any__c);
                
              semail.setccAddresses(send);
              semail.setToAddresses(sendTo);
                
           }
           else if(cc.Distributor__r.E_mail__c !=null && cc.Distributor__r.CC_to_if_any__c == null)
            {
                
              sendTo.add(cc.Distributor__r.E_mail__c);
               
                   semail.setToAddresses(sendTo);
         }
       
        
                mails.add(semail);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
        }
    }    
  
    
    @auraEnabled
     public static void sendMailWith(String recordId,String mMail){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            sendTo.add(mMail);
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
           
            //sendTo.add(cc.Distributor__r.E_mail__c);
              List<String> send = new List<String>();
            if(cc.Distributor__r.CC_to_if_any__c != null)
            {
                 send.add(cc.Distributor__r.CC_to_if_any__c);
                 
            }
         
            mails.add(semail);
            semail.setCcAddresses(send);
            semail.setToAddresses(sendTo);
            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
            system.debug('email send');
        }
    }    
  
    
     @auraEnabled
   public static void Mail(String recordId,String mMail,boolean checkCmp){
        
        for(Invoice__c cc : [select Id,Distributor__r.E_mail__c,Distributor__r.CC_to_if_any__c,Distributor__r.Name from Invoice__c WHERE Id =: recordId]){
            list<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();  
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();//to string
           
              system.debug(checkCmp);  
           
       //     semail.setToAddresses(sendTo);
          //shrutinigam1998@gmail.com  
        
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            PageReference pref = page.PdfEmailInvoice;
            pref.getParameters().put('Id',recordId);
            pref.setRedirect(true);
            Blob b;
            b = pref.getContent();
            attach.setFileName('Invoice.pdf');
            attach.setBody(b);
            semail.setSubject('Invoice details');
            semail.setReplyTo('noreply@gmail.com');
            semail.setSenderDisplayName('salesforce User');
            
            
            
           if(checkCmp==true)
               {
                  sendTo.add(mMail);
                   semail.setToAddresses(sendTo);
               }
           else  if(checkCmp==false)
            {
               system.debug('hi check'+checkCmp);
              if(mMail != null)
            {
                 system.debug('hi mMail'+mMail);
                sendTo.add(mMail);
                semail.setToAddresses(sendTo);
            }
                
             if(cc.Distributor__r.E_mail__c != null)
            { system.debug('hi Distributor mail'+cc.Distributor__r.E_mail__c);
               sendTo.add(cc.Distributor__r.E_mail__c);  
                semail.setToAddresses(sendTo);
            } 
                
             if(cc.Distributor__r.CC_to_if_any__c != null)
   
            { 
                system.debug('hi Distributor cc mail'+cc.Distributor__r.CC_to_if_any__c);
                List<String> send = new List<String>();//cc string
                send.add(cc.Distributor__r.CC_to_if_any__c);  
               semail.setCcAddresses(send);
           }   
                
                
                
            }
            
      
            mails.add(semail);

            String emailBody =' <html><body><p> Dear '+ cc.Distributor__r.Name+' ,<br><br> Please find the attached Invoice details. <br><br>    Regards, <br> IT Team <br>  Sayaji Groups.</p></body></html>';
            semail.setHtmlBody(emailBody);
            semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
            system.debug('email send');
        }
    }       
}
Hi Everyone this is my trigger i want to write test class for this so please help me i tried but not accomplish my requirement code coverge approx 75%



trigger Distributor on Account (before insert) {
    
String role;   
String owner;
    
  list<Account> changeOwner=new list<Account>();
    
    for(Account acc:trigger.new){
        
       if(acc.Under__c=='Chhattisgarh'){
           role=' CG';
          changeOwner.add(acc);
       }
      
       else if(acc.Under__c=='Bihar'){
           role=' BI';
         changeOwner.add(acc);
       }  
        
      else if(acc.Under__c=='Rajasthan') {
           role=' RJ';
           changeOwner.add(acc);
           }  
      else if(acc.Under__c=='Gujarat'){
           role=' GJ';
          changeOwner.add(acc);
           }
        
      else if(acc.Under__c=='Haryana'){
           role=' HR';
         changeOwner.add(acc);
           
       }
        
      else if(acc.Under__c=='Jharkhand'){
           role=' JH';
         changeOwner.add(acc);
       } 
        
      else if(acc.Under__c=='Maharashtra'){
           role=' MH';
         changeOwner.add(acc);
       }
        
       else if(acc.Under__c=='Madhya Pradesh'){
           role=' MP';
         changeOwner.add(acc);
       }  
       else if(acc.Under__c=='Uttar Pradesh'){
           role=' UP';
        changeOwner.add(acc);
       } 
        
   }
    String SOSTR = String.valueOf('SO') + String.valueOf(role);  
    String ASMSTR = String.valueOf('ASM') + String.valueOf(role);
    String DRMSTR = String.valueOf('DRM') + String.valueOf(role);
    String RMSTR = String.valueOf('RM') + String.valueOf(role);


  list <User> socg1=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :SOSTR Order By FirstName,LastName');
  list <User> socg2=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :ASMSTR Order By FirstName,LastName');
  list <User> socg3=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :DRMSTR  Order By FirstName,LastName');
  list <User> socg4=Database.query('SELECT Id,Name FROM User WHERE UserRole.Name = :RMSTR Order By FirstName,LastName');
  
   if(socg1.size()>0){
        owner=socg1.get(0).id;
    }
    
     else if(socg1.size()<=0){
     
        if(socg2.size()>0){
            owner=socg2.get(0).id; 
        }
        
        else if(socg2.size()<=0){
            
            if(socg3.size()>0){
              owner=socg2.get(0).id;  
             }
        
        else if(socg3.size()<=0){
            
             if(socg4.size()>0) {
               owner=socg4.get(0).id;   
             }   
        }
      }
   }
    
   for(Account acc:changeOwner){
       
        if(socg1!=null){
            acc.OwnerId=Owner;
        }
           
    }
   
}

Hi Everyone Please help me out from this scenario

 I want to update Account record owner incase custom state field is anyone selected from picklist(Gujarat,Rajasthan,Bihar,etc) with higher role and role checked 

User-added image
four levels above in role hiearchy if state chandigarh is select then (SOCG (SalesOfficer Chandigarh)) in this role the user will be updated on record owner and if no user in role of (SOCG) then above him(ASM CG) user is update on record owner this level go up to last level at (RM CG) 
and if RMCG in this role there is no user then by default  record owner will be update to this role user(RM CG)
 
i Everyone i am new in Salesforce 
So Please Help Me Out From this Scenario 

I have a two Custom Field on a Custom Object
1.ZipCode(Text)   

   Api Name=Zip_Code__c

2.Owner(Lookup User)
 

  Api Name=Owner

On Territory(Territory__c) Custom Object


My Condition is When i Insert a Zip Code like example:
1.332713=Aaron(Owner)
2.332713=Blake(Owner)
3.332713=Denise(Owner)

When i again insert 332713 and assign to a new Owner then Display a error we can not Assign a zipcode to this user Only a single zipcode is assigned to only three Owners(Sales Representatives)
Three Sales Representatives at most can be assigned to a single zipcode.Display an error if a user attempts to associate another sales representative to a zipcode

Please Replay As Soon Possible I dont know how to over come from this scenario so Please help me 

Thanks 
Neeraj Sharma
 
Hi Everyone 
I am New in Salesforce I am Beginner
So Please Help Me Out For this Scenario1
When an Account's BillingPostalCode is changed:
1.Change the Account Owner to the Sales Representative assigned to the new zip code

Sales Representative is in Another Object Territory(Territory__c)
in this object two Fileds one is ZipCode(Text) and other One is Owner(Lookup Field (User Lookup))
In First Requirement Change the Account Owner to the Owner Field in Territory and BillingPostalCode is also Mapp from ZipCode in territory Object and then Assign the AccountOwner to the Owner(Lookup) of Territory Object

2.Change the Owner field of all the Account’s Contacts to the same OwnerFiled in Territory Object(Sales Representative).

3.Change the Owner field of all the Account’s Open Opportunities to the same OwnerFiled in Territory Object(Sales Representative).


Please Replay as Soon Possible
How to use trigger i dont know about trigger So Please Help me out for this Scenario  this is my First Trigger to write So Please Help

Thanks in Advance       
Neeraj Sharma