• Inspire Dogs
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Got Issue In Below Code.
if((
                   Schema.SObjectType.Custom_Setting__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.UserName__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Password__c.isCreateable() ) ||
                                      
                   (Schema.sObjectType.Custom_Setting__c.isUpdateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isUpdateable()  ) {
                   
                   
                    Custom_Setting__c cs = new Custom_Setting__c(UserName__c = username, Password__c = password, Name = usr.Name);
                    upsert cs Name;
                   
                   }
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;
        }
    }
           
}
 
Hi,

This was working perfectly fine from past so many months and suddenly 2 days back this started throwing an error while executing test classes.

Code to execute
List<Contact> listContact = ContactTestDataFactory.createContact(1, 'FirstName', 'LastName'); insert listContact;

ContactTestDataFactory Test Class -
//Create Contact object 
public static List<Contact> createContact(Integer no_of_contact,String FirstName, String LastName){ 

List<String> lstSalutation = new List<String>{'Mr.','Ms.','Mrs.','Miss.','Dr.','U.S. Senator','U.S. Representative','Governor','Governor’s Cabinet Secretaries','Attorney General','State Senator','State Representative','Judge','Mayor','Consul-General','Ambassador','Ambassador to the U.S.','President of a Country','Former President','Lady','Police Chief','Chief Marshal','Dean','Professor','Priest','Pastor','Monsignor','Cantor','Rabbi','Nun or Sister','Brother','Bishop','Cardinal','Swami'}; 

List<Contact> listContact= new List<Contact>(); Contact objCon = new Contact(); 

for(Integer i=0;i<no_of_contact ;i++){ 
objCon = new Contact(); 
objCon.FirstName= FirstName; 
objCon.LastName= LastName; 
objCon.Salutation= lstSalutation[i]; objCon.Giving_Status__c= 'Prospect'; objCon.npe01__Primary_Address_Type__c = 'Residence'; objCon.MailingStreet = 'test'+i; 
objCon.Street_2__c = 'test 2'+i; objCon.MailingState='test'+i; objCon.MailingCity='test'+i; objCon.MailingCountry='test'+i; 
objCon.Gender__c = 'Female'; 
objCon.FirstName= FirstName; if(i/2 == 0){ objCon.Gender__c= 'Male'; 
} 
else{ 
objCon.Gender__c= 'Female'; 
} 
objCon.Unique_ID__c = String.valueOf(i); listContact.add(objCon); 
} 
System.debug('listContact'+listContact); 
return listContact; 
}

ERROR thrown - 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, npsp.TDTM_Contact: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

(npsp)






: []

Any help would be really really appreciated.

I checked other post from Stackexcahnge as well and tried work around but no luck yet.
Stack excahnge similar issue link - https://salesforce.stackexchange.com/questions/79799/how-to-debug-the-mysterious-duplicate-value-found-unknown-duplicates-value-o


--
Kind Regards
Mustafa
Hi,

I am new to Lightning Component with fair knowledge in Apex and VF. I have a custom object(B) that is lookup relationship field to the Contact record. I want to create a Lightning Component to display the Contact's related custom object (B) in Gmail (Lightning for Gmail side panel). So whenever I access an Email, the component will display that contact's related custom object. Please help with the code! Thanks.
  • July 25, 2018
  • Like
  • 2
I am creating a form in Visualforce. Since my form is a bit long, it is hard for users to remember the error message at the top and revise it. On top of the error message, I want to create a validation when users typing in their information.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.