• Miledccs Smith
  • NEWBIE
  • -1 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
public  class InvoiceDetails_custom {
    
    @AuraEnabled
    public static string  InsertInvoiceDetails(String loanApplicationId, date InvoiceDate, string InvoiceNo,decimal CashOnHire,string InvoiceType,String ChasisNumber,String EngineNumber) {
        
        String Message1='invoice number found';
        String Message2='invoice number found';
        String Message3='inserted';
        String Message4='Locked';
        boolean found=false;
        list<Invoice_Details__c> Invdetails=[select id,Invoice_Date__c,Invoice_No__c,Invoice_Approval_Status__c from Invoice_Details__c where Loan_Application__c=:loanApplicationId];
        
        boolean isCurrentInvoiceApproved = false;   
        
        if(Invdetails != null && Invdetails.size() > 0){
            if(Invdetails[0].Invoice_Approval_Status__c != null &&  Invdetails[0].Invoice_Approval_Status__c == 'Approved' ){
                isCurrentInvoiceApproved = true;
            }
        }
        //getting the dealer details based on the passed opportunty ID
        List<string> dealername = new List<string>();
        list<opportunity> dealerDetails=[select id,Name,Dealer__c,RecordType.developername from opportunity where id=:loanApplicationId];
        String recordTypeName=dealerDetails[0].RecordType.developername;
        system.debug('recordTypeName--->' +recordTypeName);
        for(opportunity op:dealerDetails)
        {
            dealername.add(op.Dealer__c);
        }
        //get the numberof opportuniies based on the dealer name
        list<ID> opIdList= new list<ID>();
        list<opportunity> oppdetails=[select id,Name from opportunity where Dealer__c In:dealername];
        for(opportunity op1:oppdetails)
        {
            opIdList.add(op1.Id);
        }
        system.debug('list***' +opIdList.size());
        list<Invoice_Details__c> InvdetailsOnOpp=[select id,Invoice_Date__c,Invoice_No__c,Invoice_Approval_Status__c,Chasis_Number__c,Engine_number__c from Invoice_Details__c where Loan_Application__c In:opIdList];
        system.debug('++++InvdetailsOnOpp+++' +InvdetailsOnOpp.size());
        for(Invoice_Details__c inv1:InvdetailsOnOpp)
        {
            if(recordTypeName == 'Consumer_Durable' && inv1.Invoice_No__c==InvoiceNo && !isCurrentInvoiceApproved)
            {
                system.debug('inv1.Invoice_Approval_Status__c' +inv1.Invoice_Approval_Status__c);
                
                system.debug('entered Consumer_Durable state');
                found=true;
                system.debug('found' +found);
                return Message2;
            }
            else if(recordTypeName == 'Two_Wheeler' && !isCurrentInvoiceApproved && (inv1.Invoice_No__c==InvoiceNo || inv1.Chasis_Number__c ==ChasisNumber || inv1.Engine_number__c == EngineNumber))
            {
                system.debug('entered two wheeler state');
                found=true;
                system.debug('found' +found);
                return Message2;
            }
        }
        
        
        //list<Invoice_Details__c> invDetails= new list<Invoice_Details__c >();
        if(!found){
            list<Invoice_Details__c> Invdetail=[select id,Invoice_Date__c,Invoice_No__c  from Invoice_Details__c where Loan_Application__c=:loanApplicationId];
            system.debug('not found state');    
            if(Invdetail.isEmpty())
            {
                try{
                    Invoice_Details__c c = new Invoice_Details__c();
                    c.Invoice_Date__c=InvoiceDate;
                    c.Invoice_No__c=InvoiceNo;
                    c.Invoice_Type__c=InvoiceType;
                    c.Loan_Application__c=loanApplicationId;
                    c.Invoice_Amount__c=CashOnHire;
                    c.Chasis_Number__c=ChasisNumber;
                    c.Engine_number__c=EngineNumber;
                    insert c;
                    return Message3; 
                }
                catch(Exception e)
                {
                    System.debug('Exception type caught: ' + e.getTypeName());    
                    System.debug('Message: ' + e.getMessage());    
                    System.debug('Cause: ' + e.getCause());    // returns null
                    System.debug('Line number: ' + e.getLineNumber());    
                    System.debug('Stack trace: ' + e.getStackTraceString());
                    system.debug('error message' +e.getMessage());
                    return e.getMessage();
                }
                
            }
            else{
                // string Approved='Locked';
                // string Approved=Invdetail[0].Approved__c;
                Id InvoiceId = Invdetail[0].id;    
                try{
                    Invoice_Details__c c = new Invoice_Details__c();
                    Invoice_Details__c invoicedet=[select id,Invoice_Date__c,Invoice_No__c,Invoice_Type__c,Invoice_Amount__c from Invoice_Details__c where id=:InvoiceId];
                    c.Id=invoicedet.id;
                    c.Invoice_Date__c=InvoiceDate;
                    c.Invoice_No__c=InvoiceNo;
                    c.Invoice_Type__c=InvoiceType;
                    //c.Loan_Application__c=loanApplicationId;
                    c.Invoice_Amount__c=CashOnHire;
                    c.Chasis_Number__c=ChasisNumber;
                    c.Engine_number__c=EngineNumber;
                    update c;
                    return Message3;
                }
                catch(Exception e)
                {
                    System.debug('Exception type caught: ' + e.getTypeName());    
                    System.debug('Message: ' + e.getMessage());    
                    System.debug('Cause: ' + e.getCause());    // returns null
                    System.debug('Line number: ' + e.getLineNumber());    
                    System.debug('Stack trace: ' + e.getStackTraceString());
                    system.debug('error message' +e.getMessage());
                    return e.getMessage();
                    
                }
            }
        }
        
        return Message3;
    }
    
    public class InvoiceDetailswrapper{
        @AuraEnabled
        public opportunity opportuntyObject {get;set;}
        @AuraEnabled
        public list<Invoice_Details__c> invoiceList {get;set;}
    }
    @AuraEnabled
    public static InvoiceDetailswrapper  getLoanApplicationdetails(String loanApplicationId) {
        String test='test';
        InvoiceDetailswrapper invoiceWrapper = new InvoiceDetailswrapper();
        
        list<opportunity> details=[select id,Name,RecordType.developername from opportunity where id=:loanApplicationId];
        if(details.size()!= null && details.size() >0)
        {
            invoiceWrapper.opportuntyObject = details[0];
        }
        list<Invoice_Details__c> InvdetailsOnOpp=[select id,Invoice_Date__c,Invoice_No__c,Invoice_Amount__c,Loan_Application__r.name,Invoice_Type__c,Invoice_Approval_Status__c,Chasis_Number__c,Engine_number__c from Invoice_Details__c where Loan_Application__c =:loanApplicationId];
        system.debug('invdetaisl***' +InvdetailsOnOpp);
        if(InvdetailsOnOpp.size()!= null && InvdetailsOnOpp.size() >0)
        {
            invoiceWrapper.invoiceList=InvdetailsOnOpp;
        }
        
        system.debug('***loan details2' +InvdetailsOnOpp);
        return invoiceWrapper;
    }
    
    @AuraEnabled
    public static String Newinvoice(String loanApplicationId, date InvoiceDate, string InvoiceNo,decimal CashOnHire,string InvoiceType,String ChasisNumber,String EngineNumber)
    {
        
        list<Invoice_Details__c> Invdetail=[select id,Invoice_Date__c,Invoice_No__c from Invoice_Details__c where Loan_Application__c=:loanApplicationId];
        if(Invdetail.isEmpty())
        {
            try{
                Invoice_Details__c c = new Invoice_Details__c();
                c.Invoice_Date__c=InvoiceDate;
                c.Invoice_No__c=InvoiceNo;
                c.Invoice_Type__c=InvoiceType;
                c.Loan_Application__c=loanApplicationId;
                c.Invoice_Amount__c=CashOnHire;
                c.Chasis_Number__c=ChasisNumber;
                c.Engine_number__c=EngineNumber;
                
                insert c;
                String result1=Approval(loanApplicationId,c.Id); 
                return result1;
                //salesmanger details for the opporunity
            }catch(Exception e)
            {
                return e.getMessage();
            }
        }
        else{
            system.debug('***********entered update condition');
            try{
                Id InvoiceId = Invdetail[0].id;    
                Invoice_Details__c c = new Invoice_Details__c();
                Invoice_Details__c invoicedet=[select id,Invoice_Date__c,Invoice_No__c,Invoice_Type__c,Invoice_Amount__c from Invoice_Details__c where id=:InvoiceId];
                c.Id=invoicedet.id;
                c.Invoice_Date__c=InvoiceDate;
                c.Invoice_No__c=InvoiceNo;
                c.Invoice_Type__c=InvoiceType;
                //c.Loan_Application__c=loanApplicationId;
                c.Invoice_Amount__c=CashOnHire;
                c.Chasis_Number__c=ChasisNumber;
                c.Engine_number__c=EngineNumber;
                update c;
                system.debug('updated' +c.Id);
                String result2=Approval(loanApplicationId,c.Id);
                return result2;
            }catch(Exception e)
            {
                return e.getMessage();
            }
        }        
    }
    
    @AuraEnabled
    public static String Approval(String loanApplicationId,id objectID)
    {
        
        
        List<Id> Approver = new List<Id>();
        list<user> userList=[select Id,Name,Profile.UserLicense.Name,ManagerID,Manager.Name from User where  id=:UserInfo.getUserId() AND isActive=true];
        String UserLicense = userList[0].Profile.UserLicense.Name;
        String ManagerID= userList[0].ManagerID;
        //list<user> ManagerUser= [select id,ManagerID, Manager.Name from user where ManagerID =:ManagerID];
        
        
        //String managerName= u[0].Manager;
        system.debug('userlicense' +UserLicense);
        for(user op3:userList)
        {
            if(op3.Profile.UserLicense.Name == 'Salesforce' )
            {
                Approver.add(op3.Id);
                string approvedMessage = 'success';
                return approvedMessage;
            }
            else if(op3.Profile.UserLicense.Name == 'Partner Community')
            {
                
                system.debug('***Manger name-->' +op3.Profile.UserLicense.Name);
                Id UserID= getUserId(ManagerID);
                system.debug('UserID' +UserID);
                //Approver.add(op3.ManagerID);
                if(UserId == null)
                {
                    system.debug('***user id is null');
                    String message='no userId found';
                    return message;
                }
                else
                {
                    system.debug('***user id is not null');
                    Approver.add(UserId);
                    
                }
            }
            
            
        }
        system.debug('Approver---->ID' +Approver);
        //  system.debug('salesofficer' +so);
        list<Invoice_Details__c> invdetailsUpdate=[select id,Approver__c from Invoice_Details__c where Loan_Application__c=:loanApplicationId];
        user userdetails=[select id,name from user where id in:Approver];
        Invoice_Details__c c = new Invoice_Details__c();
        c.Id=objectID;
        c.Approver__c=userdetails.name;
        update c;
        system.debug('userDetails' +userdetails);
        system.debug('InvoiceDetailsResult' +c); 
        //approval process 
        // system.debug(so);    
        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        req.setObjectId(objectID);
        req.setProcessDefinitionNameOrId('DuplicateInvoiceNumber');
        //List<Id> appList = new List<Id>();
        //appList.add('0056F0000082Ooo');
        req.setNextApproverIds(Approver);
        req.setSkipEntryCriteria(true);
        
        Approval.ProcessResult processResult = Approval.process(req);
        system.debug('****status' +processResult.getInstanceStatus());
        string StatusResult = processResult.getInstanceStatus();
        
        
        String message1='success';
        return message1;
    }
    
    public static Id getUserId(string ManagerID)
    {
        system.debug('***managerName**' +ManagerID);
        list<user> managerlist =[select id,Profile.UserLicense.Name,ManagerId,Manager.Name from user where Id=:ManagerID And isActive=true];
        system.debug('userList' +managerlist);
        
        if(managerlist[0].Profile.UserLicense.Name == 'salesforce')
        {
            system.debug('***manager id is null' +managerlist[0].Profile.UserLicense.Name);
            return managerlist[0].id;
        }
        else if(managerlist[0].Profile.UserLicense.Name == 'Partner Community'){
            system.debug('***partner comunity' +managerlist[0].Profile.UserLicense.Name);
            if(managerlist[0].ManagerId != null){
                system.debug('managerlist[0].Manager.Name' +managerlist[0].Manager.Name);
                getUserId(managerlist[0].ManagerId);
            }else{
                return null;
            }
            
        }
        
        return null;
    }

    @AuraEnabled
    public static list<Invoice_Details__c> getApproverDetails(String loanApplicationId)
    {
          list<Invoice_Details__c> InvApproverList=[select id,Invoice_Date__c,Invoice_No__c,Approver__c,Invoice_Approval_Status__c from Invoice_Details__c where Loan_Application__c=:loanApplicationId];
        if(InvApproverList.size() != null)
        {
          system.debug('&&&InvApproverList--' +InvApproverList);
                return InvApproverList;
            }
        else{
        return null;
        }
    }
           
}
 
Hello all

I want to  send an automatic email when lead status is converted to "Qualified" , i tried it in workflow and process, it worked fine, now i want to try it in apex , i have ready made email template named "XXX" which shows as 

Hello {!Lead.LastName} 

Thank you for the registering with us 
Soon we will get back to you 

Team EduProserra

my apex class is

public class emailSending {

    public String Lead { get; set; }
    public string toMail { get; set;}
    public string ccMail { get; set;}
    public string repMail { get; set;}
    
    public void sendMail(){
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string[] to = new string[] {toMail};
        string[] cc = new string[] {ccMail};
        
        email.setToAddresses(to);
        if(ccMail!=null && ccMail != '')
            email.setCcAddresses(cc);
        if(repmail!=null && repmail!= '')
            email.setInReplyTo(repMail);
        
        email.setSubject('Thank you for the Registration');
        
        email.setHtmlBody('Hello, {!Lead.LastName} <br/><br/>Thank you for Registration. <br/>We will get back to you for more details<br/><br/>Regards<br/> EduPro Team');
        try{
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }catch(exception e){
            apexpages.addmessage(new apexpages.message(apexpages.severity.error,e.getMessage()));
        }
        
        toMail = '';
        ccMail = '';
        repMail = '';
    }
}

how do i design a trigger for this??
I'm a bit frustrated.  I've been progressing well with the Superbadge, but the report stuff seems to not be working.  I've researched similar questions and, although I think I'm doing the right thing, I get: The 'Users with Volunteer Shift Worker Records' Custom Report Type does not have the correct objects assigned.
I feel like I'm missing something really simple.  I created a report type called "Users with Volunteer Shift Worker Records".   I believe the report type only needs Users (A) and Volunteer Shift Workers (B).  The "fields available" though shows 70 fields available from users and 0 available from Volunteer Shift Workers.  What am I doing wrong that would cause the challenge check to fail?
report type failure
Hi Everyone,

I need a way determine if the accountNumber field contains -1. I got it work when -1 is the only value in the account number field. The formula needs to identify identify wether -1 is present the string (i.e. 11706-1). Not sure what else I need to do here.
 
IF(  CONTAINS("-1", Site) , BillingCity , 
IF(   NOT( CONTAINS("-1", Site) ), ShippingCity , 
IF(  CONTAINS("", Site)  , ShippingCity , BillingCity) ) )

 
Hello,

I have enabled files connect and set up all the permission in my org for Files connect. I have even created one authentiction for google cloud which is running perfectly. But I have a requirement to connect it to Box account. the problem is that i am not able to see the 'Files Connect: Box' option in new external data source.

User-added image

According to the salesforce documentation, Files Connect: Box should be visible. Request everyone to help me out how to get this Files Connect: Box option

Regards,
Gaurav
Hi All,

Earlier I had the Marketing Cloud Developer Edition. I used it for development of integration between Exacttarget and Salesforce. But right now my Developer Edition account is expired. I go to the https://code.exacttarget.com/developer-edition/ and see that Developer Edition is not available for registration at this time. How to receive Developer Edition account now ? Are there the alternative solution? Please advice!