• Kunal Purohit 4
  • NEWBIE
  • 140 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 56
    Questions
  • 19
    Replies

Hello Folks,
I am learning VisualForce page. I want to create a VF page with one field and this page should make the api call/fetch the data from custom object and show it in that field. I have tried with below code but it is generating an error: 

Unknown property 'ZipCodeController.ProspectUser__c'

Here ProspectUser__c is an object name and ZipCode__c is a field name.

VF Page:

<apex:page controller ="ZipCodeController" >
    
    <apex:form>
    <apex:inputField value = "{!ProspectUser__c.ZipCode__c}"/>
    </apex:form>
</apex:page>


Controller:
public with sharing class ZipCodeController {
	
    public List<ProspectUser__c> getProspectUser{get;set;}
    
    public ZipCodeController()
    {
        getProspectUser = [Select ZipCode__c FROM ProspectUser__c LIMIT 1];
    }
    
}
 

Please suggest.

Hello All,
I am having two Fields ZipCode__c and TimeZone__c, Now whenever user enters ZipCode__c, TimeZone__c should be updated accordingly. Here I have to use REST API for ZipCode. I am new to salesforce. Please help to write the trigger for same.
Thanks.

Hello Folk,
How to update Time Zone based on ZipCode provided by User? What approach should I use? Trigger or Flow? Should I need REST API for for same? Please suggest.
Hi,
I am having an Object named ProspectUSer__c. I  want to update the timezone__c field based on AreaCode__c, StateCode__c and ZipCOde__c values at time of insert/update. But again the values of these three fields need to be get from custom metadata.? How to perform this fucntionality using configuration. Please suggest.
Hello All,
There is a custom metadata with four fields AreaCode,ZipCode,State and TimeZone. Whenever these field values are inserted/updated, TimeZone value need to be update. How to achieve this fucntionality through configuration or Lightning Flows?
Please suggest.

Hello Folks,

I want to design a custom button such that when user click on that custom button, a drop down should appear with list of emeil template, followed by editable Email Body and recipient name. Finally, clocking on Send button in dropdown, Email will be sent to recipient. How to perform this tak? Using Trigger or Lightning Flows? Plz Suggest.

Hello Folks,
Below Handler works on Round Robin manner in contact Object. Such that, when Contact record is created , it is assigned to another System Admin, based on Round Robin Manner. It is for 2 users only. What changes should I made so that it could work for multiple users. Please Suggest.

public class RoundRobinContactHandler {
		public static void AssignUser(List<Contact> cn)
        {
            integer countContact = 0;
            String usr;
            List<Contact> cnList = new List<Contact> ();
            
                 
            List<Contact> clist=[Select id, Name, Assigned_To__c from Contact where Assigned_To__r.isActive = TRUE];
            countContact=clist.size();
            integer RnRUserAssigned = Math.mod(countContact, 2) + 1;
            integer CSRindex=0;
            
            if(RnRUserAssigned==1)
            {
                usr=[Select id, name from User where Id = '0052w000002n0Pj' LIMIT 1].id;
            }
            else if (RnRUserAssigned==2)
            {
                usr=[Select id, name from User where Id = '0052w000009deaY' LIMIT 1].id;
            }
            
            if(cn.size()>0 && (usr!=null && usr!='')) 
            {
                for(Contact con : cn)
            	{
                  con.Assigned_To__c= usr;
                 
             	} 
            }
           
         }
}

Hello Follks,

How to write apex trigger for given scenario?
There are two system Admin in Org. If I am creating two contact record, each contact record should be assigned to each user. Likewise, if there are 3 System Admin, so whenever 3 Contact record is created, it should be assigned to 3 different user(Using Round Robin Technique).

Hello Folks,
There are two System Admin in my Dev Org. Whenever, I will create new Contact record, it must be assigned to another System Admin and Whenever Other System Admin will create Contact Record, it should be assigned to me. (Round Robin)

Here AssignedTo__c is a custom field with Lookup Relation data type(User).

 

Please suggest.

Hello Folks, I am trying to write test class for below code. Its not moving beyond 45%. Can you please help me to achieve the same?

public class SumAmountOppHandler {
    
     List<Account> accList=new List<Account>();
     Set<Id> setAccIds = new Set<Id>();
    public  void afterinsert(List<Opportunity> newoppylist){
  for(Opportunity con : newoppylist){
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
               updateamount(setAccIds) ;
                }
                        } 
    }
      public  void afterupdate(List<Opportunity> newoppylist, Map<Id,Opportunity> mapoppy){
    
        for(Opportunity con : newoppylist){ 
            if(con.AccountId!=mapoppy.get(con.Id).AccountId && con.Amount>10000.00){
                setAccIds.add(con.AccountId);
                setAccIds.add(mapoppy.get(con.Id).AccountId);
                updateamount(setAccIds) ;
                }
            
                        }        
        
    }
      public  void afterdelete(List<Opportunity> oldoppylist){
  for(Opportunity con : oldoppylist){
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
                updateamount(setAccIds) ;
                }
                        } 
    }
    
    public void updateamount(set<id> accids){
          for(Account acc :[Select id,Total_Opty_Amount__c  ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : accids]){
                        
        acc.Total_Opty_Amount__c  = acc.Opportunities.size();
        acclist.add(acc);
        
    }
    if(acclist.size()>0){
        update accList;     
    }
    }

}

Hello Folks,
How to write Handler for below trigger.?

trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete, After Undelete) {
 List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
    if(Trigger.isInsert){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
			}
		}
    } 
    system.debug('setAccIds ==> '+setAccIds);
    if(Trigger.isUpdate){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){ 
            if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && con.Amount>10000.00){
               	setAccIds.add(con.AccountId);
                setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
            	}
            
			}        
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.old) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    
    if(Trigger.isUndelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.new) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    for(Account acc :[Select id,Total_Opportunity__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : setAccIds]){
			
        acc.Total_Opportunity__c = acc.Opportunities.size();
        acclist.add(acc);
        
    }
    if(acclist.size()>0){
        update accList;     
    }
    
}
When an account is selected from the lookup then the account type and account billing address should be auto-populated and displayed in the screen as non-editable fields. How to perform this task using VF page
 
Hello All,
I am new to visualforce page.
I am trying to Create a VF page for Contacts with fields Salutation, FirstName, LastName, Email, AccountName (Lookup Filter). 
When an account is selected from the lookup then the account type and account billing address should be auto-populated and displayed in the screen as non-editable fields.

Kindly, suugest possible solution for this scenario.

Hello Folks, 

I am new to salesforce development. Attempting to write a test class for below code. Please suggest.
 

public class CountContactHandler {
    
    public static void ContactCheckBox(List<Contact> con) {
        
        Set<Id> setid = new Set<Id>();
        for(Contact c : con) {
            setid.add(c.AccountId);
        }
        
        List<Account> acc1 = [SELECT Id, Name From Account WHERE Id In :setid];
        
        for(Account a1 : acc1) {
            
        }
    }

}

Hello Community,

In my VF page, I want to show/Hide Custom setting Component based on User Login. Is it possible through Configuration or else It requires codig?

Marked text is a link that derives from custom setting. Please suggest solution.User-added image

Hi,
I am creating new Email Template(HTML). I want to include Approval Process step for Custom Object Client_Contract__c. I want to display:
1) Previous Approval Step name
2) Next  Approval Step name.
Please help.
Hi,
In my org, there are two objects Case and Project. Case object is having lookup relation with Project and Account Object. Now whenever, Case record is cretaed for particular Project, its asscoiated Account should get populated in case record. Plz help to write trigger for same.
Hello, Below is my Trigger:
public class AccountTeamTriggerHandler {
    static final String Team_Role_Value = 'Technical Support Manager';
    public static void handlerIsBeforeInsertUpdate(List<AccountTeamMember> newAccountList){
        map<Id,List<AccountTeamMember>> accIdVsTeamMemberMap = new  map<Id,List<AccountTeamMember>>();
        system.debug('newAccountList.size()=>'+newAccountList.size());
        for(AccountTeamMember accountTeamObj : newAccountList){
            if(accountTeamObj.TeamMemberRole.equalsIgnoreCase(Team_Role_Value)){
                if(accIdVsTeamMemberMap.containsKey(accountTeamObj.AccountId)) {
                    List<AccountTeamMember> accTeamList=accIdVsTeamMemberMap.get(accountTeamObj.AccountId);
                    accTeamList.add(accountTeamObj);
                    accIdVsTeamMemberMap.put(accountTeamObj.AccountId,accTeamList);
                }
                else{
                    accIdVsTeamMemberMap.put(accountTeamObj.AccountId,new List<AccountTeamMember>{accountTeamObj});
                }
            }
        }
        System.debug('accIdVsTeamMemberMap=='+accIdVsTeamMemberMap);
        List<Id> oldaccountIdSet = new List<Id>();
        List<AccountTeamMember> accountTeamList =[SELECT id,
                                                         TeamMemberRole,
                                                         AccountId 
                                                  FROM AccountTeamMember 
                                                  WHERE AccountId in: accIdVsTeamMemberMap.keyset() 
                                                  AND TeamMemberRole=:Team_Role_Value];
        for(AccountTeamMember oldaccountTeamObj : accountTeamList){
            oldaccountIdSet.add(oldaccountTeamObj.AccountId);
        }
        for(Id accId:accIdVsTeamMemberMap.keyset()){
            if(accIdVsTeamMemberMap.get(accId).size()>1){
                accIdVsTeamMemberMap.get(accId)[1].addError(Label.Account_team_member_error_message);
            }
            else{
                for(AccountTeamMember accTeamObj:accIdVsTeamMemberMap.get(accId)){
                    if(oldaccountIdSet.contains(accTeamObj.AccountId)){
                        accTeamObj.addError(Label.Account_team_member_error_message);
                    }
                }
            }
        }
    }
    
 
}


I have written below test class. Its code coverage is 80%. But I want to increase it to 85%. How to increase further:

/**
* Class       : AccountTeamMemberTriggerTest
* Description : Test Class for AccountTeamMemberTrigger  
* Created By  : Divergent
* Created On  : 030521
* */
@isTest
public class AccountTeamMemberTriggerTest {
    /**
    * Method Name : setupTestData
    * Description : Test data created for this test class.
    * Created By  : Divergent
    * Created On  : 030521
    * */
 @testSetup static void setupTestData() {
        List<Account> Accounts;
        Accounts = new List<Account>();
        Account acc = new Account();
        acc.Name = 'Acme Industries';
        Accounts.add(acc);
        insert Accounts;
     
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='testmemberuser@testorg.com');
     insert u;
     
 }
     /**
    * Method Name : testCreateMultipleAccountMember
    * Description : Create 2 account team member with role Technical support manager.
    * Created By  : Divergent
    * Created On  : 030521
    * */
     @isTest
    public static void testCreateMultipleAccountMember() {
        Account acc=[Select Id from Account];
        User u=[Select Id from User where UserName='testmemberuser@testorg.com'];
        AccountTeamMember accTeam=new AccountTeamMember();
        accTeam.AccountId=acc.id;
        accTeam.UserId=u.id;
        accteam.TeamMemberRole='Technical Support Manager';
        insert accteam;
        Try{
        AccountTeamMember accTeam2=new AccountTeamMember();
        accTeam2.AccountId=acc.id;
        accTeam2.UserId=u.id;
        accteam2.TeamMemberRole='Technical Support Manager';
        insert accteam2;
        }
        catch(Exception e){
            Boolean expectedExceptionThrown =e.getMessage().contains('Technical Support Manager')? true : false;
            System.AssertEquals(expectedExceptionThrown, true);
            System.Assert(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'));
        }
    }
      /**
    * Method Name : testSecondMemberAsTechnical
    * Description : Create first account with other role and then next 2 with role Technical support manager.
    * Created By  : Divergent
    * Created On  : 030521
    * */
    @isTest
    public static void testSecondMemberAsTechnical() {
        Account acc=[Select Id from Account];
        User u=[Select Id from User where UserName='testmemberuser@testorg.com'];
        List<AccountTeamMember> accountTeamMembers = new List<AccountTeamMember>();
        AccountTeamMember accTeam=new AccountTeamMember();
        accTeam.AccountId=acc.id;
        accTeam.UserId=u.id;
        accteam.TeamMemberRole='Boost Overlay Rep';
        accountTeamMembers.add(accteam);
        
        
        AccountTeamMember accTeam3=new AccountTeamMember();
        accTeam3.AccountId=acc.id;
        accTeam3.UserId=u.id;
        accteam3.TeamMemberRole='Technical Support Manager';
        accountTeamMembers.add(accteam3);
        
        //insert accountTeamMembers;
        
        Try{
            AccountTeamMember accTeam2=new AccountTeamMember();
            accTeam2.AccountId=acc.id;
            accTeam2.UserId=u.id;
            accteam2.TeamMemberRole='Technical Support Manager';
            accountTeamMembers.add(accteam2);
            
            insert accountTeamMembers;
        }
        catch(Exception e){
            Boolean expectedExceptionThrown =e.getMessage().contains('Technical Support Manager')? true : false;
            System.AssertEquals(expectedExceptionThrown, true);
            System.Assert(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'));
        }
    }
    
}

Hello, I am new to salesforce development. I want to write test class for given apex controller. Please help.

public without sharing class CreateNachaFileController {
	public String key;
	private ApexPages.StandardSetController standardController;
	public string headerImmediateDestination { get; set; }
	public string headerImmediateOrigin { get; set; }
	public string headerFileIdModifier { get; set; }
	public string headerDestinationName { get; set; }
	public string headerImmediateOriginName { get; set; }
	public string batchCompanyName { get; set; }
	public string batchCompanyId { get; set; }
	public string batchOriginatingDfiID { get; set; }
	public string batchCompanyEntryDescription { get; set; }
	public string batchCompanyDescriptiveDate { get; set; }
	public NachaFile nacha { get; set; }
	public Integer TotalCount { get; set; }
	public Decimal Total { get; set; }
	public String ServiceClass { get; set; }
	public Invoice_Header__c invoice { get; set; }
	public Customer_Payment__c NewPayment { get; set; }
	public List<SelectOption> nachaDefaultNames { get; set; }
	public String selectedNachaDefaultName { get; set; }
	public Boolean hasSplits { get; set; }
	private Map<String, CS_Nacha_Defaults__c> nachaDefaults;
	public Map<Id, InvoiceSplitWrapper> splitWrappers { get; set; }


	/////////////////////////////////////////////////////////////////
	// Outgoing (Vendor) NACHA
	/////////////////////////////////////////////////////////////////
	/**
	 * @description Constructor when called from Visualforce page as an extension, like CreateNachaFile
	 * @param standardController 
	 */
	public CreateNachaFileController(ApexPages.StandardSetController standardController) {
		if (this.standardController == null) {
			this.standardController = standardController;
			InitializeDefaults();
			headerFileIdModifier = 'A';
		}
	}

	public PageReference CreateNachaFile1() {
		return Page.CreateNachaFile;
	}

	public PageReference CreateNachaFile2() {
		TotalCount = 0;
		Decimal totalCalc = 0.0;
		Total = 0.0;
		Id[] ids = new List<Id> ();
		for (Vendor_Payment__c payment : (List<Vendor_Payment__c>) standardController.getSelected()) {
			ids.add(payment.Id);
			TotalCount++;
			if (payment.Total__c != null) { totalCalc = totalCalc + payment.Total__c; }
		}
		Total = totalCalc.setScale(2);

		nacha = new NachaFile();
		nacha.headerData.headerImmediateDestination = headerImmediateDestination.left(10);
		nacha.headerData.headerImmediateOrigin = headerImmediateOrigin.left(10);
		nacha.headerData.headerFileIdModifier = headerFileIdModifier.left(1);
		nacha.headerData.headerDestinationName = headerDestinationName.left(23);
		nacha.headerData.headerImmediateOriginName = headerImmediateOriginName.left(23);

		nacha.headerData.batchCompanyEntryDescription = batchCompanyEntryDescription == null ? '' : batchCompanyEntryDescription.left(10);
		nacha.headerData.batchCompanyName = batchCompanyName.left(16);
		nacha.headerData.batchCompanyId = batchCompanyId.left(10);
		nacha.headerData.batchOriginatingDfiID = batchOriginatingDfiID.left(8);

		nacha.headerData.serviceClass = ServiceClass;

		nacha.generateFile(ids);

		return Page.CreateNachaFile2;
	}

	public PageReference CreateNachaFile3() {
		// Create Nacha_File__c record
		NACHA_File__c nf = new NACHA_File__c();
		nf.Destination_Name__c = nacha.headerData.headerDestinationName;
		nf.File_Id_Modifier__c = nacha.headerData.headerFileIdModifier;
		nf.Generated_By__c = UserInfo.getUserId();
		nf.Immediate_Destination__c = nacha.headerData.headerImmediateDestination;
		nf.Immediate_Origin__c = nacha.headerData.headerImmediateOrigin;
		nf.Immediate_Origin_Name__c = nacha.headerData.headerImmediateOriginName;
		nf.Service_Class__c = nacha.headerData.serviceClass;
		insert nf;
		List<Vendor_Payment__c> payment = (List<Vendor_Payment__c>) standardController.getSelected();
		for (Vendor_Payment__c detail : payment) {
			detail.Status__c = 'Payment Sent';
			detail.Date_Paid__c = Date.today();
			detail.NACHA_File__c = nf.Id;
		}
		standardController.save();
		return Page.CreateNachaFile3;
	}

	public PageReference cancel() {
		Schema.DescribeSObjectResult anySObjectSchema = Vendor_Payment__c.SObjectType.getDescribe();
		String objectIdPrefix = anySObjectSchema.getKeyPrefix();
		PageReference pageReference = new PageReference('/' + objectIdPrefix + '/o');
		pageReference.setRedirect(true);
		return pageReference;
	}

	/////////////////////////////////////////////////////////////////
	// Incoming (Customer) NACHA
	/////////////////////////////////////////////////////////////////
	/**
	 * @description Constructor when called from Visualforce page as Controller - CreateIncomingNachaFile.page
	 */
	public CreateNachaFileController() {
		InitializeDefaults();
		headerFileIdModifier = 'H';
		batchCompanyEntryDescription = 'RECEIVABLE';
		batchCompanyDescriptiveDate = string.valueof(DateTime.now().month()) + string.valueof(DateTime.now().year()).substring(2, 4);

		invoice = [SELECT
		           Id, Name, Customer_Id__c, Customer_Name__c, Invoice_Total__c, Total_Balance__c, Document_Date__c, Memo__c,
		           Customer_ID__r.Bank_Account__c, Customer_ID__r.Bank_Routing__c, Customer_Id__r.Receivables_Account_Id__c, Customer_ID__r.NACHA_Vendor_NameFx__c
		           , (select Id, Name, Invoice_Split_Amount__c, Bank_Information__r.Name, Bank_Information__r.Bank_Account__c, Bank_Information__r.Bank_Routing__c, Exclude_from_NACHA_Files__c from Invoice_Splits__r)
		           FROM Invoice_Header__c
		           where Id = :key];

		hasSplits = invoice.Invoice_Splits__r.size() > 0;

		NewPayment = new Customer_Payment__c();
		NewPayment.Customer_Id__c = invoice.Customer_Id__c;
		NewPayment.Tran_Date__c = Date.today() + 1;
		NewPayment.Default_Vendor_Payment_Date__c = PaymentFromCustomerController.calculateNthWorkingDay(Date.today() + 1, 1);
		NewPayment.AR_Account_Id__c = invoice.Customer_Id__r.Receivables_Account_Id__c;
		NewPayment.Payment_Type__c = 'ACH';

		NewPayment.Amount__c = invoice.Total_Balance__c;
		System.debug(hasSplits);
		if (hasSplits) {
			NewPayment.Amount__c = 0;
			splitWrappers = new Map<Id, InvoiceSplitWrapper> ();
			for (Invoice_Split__c split : invoice.Invoice_Splits__r) {
				System.debug(split);
				System.debug(split.Exclude_from_NACHA_Files__c);
				if (split.Exclude_from_NACHA_Files__c == false) {
					System.debug('included');
					InvoiceSplitWrapper splitWrapper = new InvoiceSplitWrapper(split);
					splitWrapper.checked = true;
					splitWrappers.put(splitWrapper.invoiceSplit.Id, splitWrapper);
					NewPayment.Amount__c += split.Invoice_Split_Amount__c;
					System.debug(NewPayment.Amount__c);
				}
			}
		}
		System.debug(splitWrappers);

	}
	public PageReference CreateIncomingNachaFile1() {
		return Page.CreateIncomingNachaFile;
	}

	public PageReference CreateIncomingNachaFile2() {
		if (NewPayment.Amount__c == null || NewPayment.Tran_Date__c == null) {
			ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Amount and Payment Date are required before saving.');
			ApexPages.addMessage(myMsg);
			return null;
		}
		if (hasSplits) {
			NewPayment.Amount__c = 0;
			for (Id key : splitWrappers.keySet()) {
				InvoiceSplitWrapper sw = splitWrappers.get(key);
				if (sw.checked) {
					NewPayment.Amount__c += sw.invoiceSplit.Invoice_Split_Amount__c;
				}
			}
		}
		TotalCount = 0;
		Decimal totalCalc = 0.0;
		Total = 0.0;
		TotalCount = 1;
		totalCalc = NewPayment.Amount__c; //invoice.Total_Balance__c;
		Total = totalCalc.setScale(2);

		nacha = new NachaFile();
		nacha.headerData.headerImmediateDestination = headerImmediateDestination.left(10);
		nacha.headerData.headerImmediateOrigin = headerImmediateOrigin.left(10);
		nacha.headerData.headerFileIdModifier = headerFileIdModifier.left(1);
		nacha.headerData.headerDestinationName = headerDestinationName.left(23);
		nacha.headerData.headerImmediateOriginName = headerImmediateOriginName.left(23);

		nacha.headerData.batchCompanyName = batchCompanyName.left(16);
		nacha.headerData.batchCompanyId = batchCompanyId.left(10);
		nacha.headerData.batchOriginatingDfiID = batchOriginatingDfiID.left(8);
		nacha.headerData.batchCompanyEntryDescription = batchCompanyEntryDescription.left(10);
		nacha.headerData.batchCompanyDescriptiveDate = batchCompanyDescriptiveDate.left(6);

		nacha.headerData.serviceClass = ServiceClass;
		nacha.AmountOverride = NewPayment.Amount__c;
		nacha.PaymentDate = NewPayment.Tran_Date__c;
		System.debug(nacha);
		System.debug(splitWrappers);
		nacha.generateIncomingFile(new List<Invoice_Header__c> { invoice }, splitWrappers);

		return Page.CreateIncomingNachaFile2;
	}

	public PageReference CreateIncomingNachaFile3() {
		//Save New Payment, then save nacha file
		if (!CreateNewPayment()) return null;
		return Page.CreateIncomingNachaFile3;
	}

	// Incoming (Customer) NACHA
	public void actionSupportChangePmtDivision() {
		Id glAccount = null;
		Id pmtDivisionId = NewPayment.Payment_Division_Id__c;
		List<Payment_Division__c> pmtDivisions = [SELECT Id, Name, GL_Account_Id__c FROM Payment_Division__c WHERE Id = :pmtDivisionId];
		NewPayment.GL_Account_Id__c = null;
		if (pmtDivisions.size() != 0) {
			for (Payment_Division__c pd : pmtDivisions) {
				NewPayment.GL_Account_Id__c = pd.GL_Account_Id__c;
			}
		}
	}
	// Incoming (Customer) NACHA
	public boolean CreateNewPayment() {
		// Create Nacha_File__c record
		NACHA_File__c nf = new NACHA_File__c();
		//nacha.Name = 
		nf.Destination_Name__c = nacha.headerData.headerDestinationName;
		nf.File_Id_Modifier__c = nacha.headerData.headerFileIdModifier;
		nf.Generated_By__c = UserInfo.getUserId();
		nf.Immediate_Destination__c = nacha.headerData.headerImmediateDestination;
		nf.Immediate_Origin__c = nacha.headerData.headerImmediateOrigin;
		nf.Immediate_Origin_Name__c = nacha.headerData.headerImmediateOriginName;
		nf.Service_Class__c = nacha.headerData.serviceClass;
		insert nf;

		if (!hasSplits) {
			if (NewPayment.Amount__c == null || NewPayment.Tran_Date__c == null) {
				ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Amount and Payment Date are required before saving.');
				ApexPages.addMessage(myMsg);
				return false;
			}

			decimal totalAmountApplied = NewPayment.Amount__c;
			NewPayment.NACHA_File__c = nf.Id;
			insert NewPayment;
			Customer_Payment_Apply__c application = new Customer_Payment_Apply__c();
			application.Customer_Payment_Id__c = NewPayment.Id;
			application.Invoice_Id__c = invoice.Id;
			application.Amount__c = NewPayment.Amount__c;
			insert application;
			return true;
		} else {
			if (NewPayment.Tran_Date__c == null) {
				ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'Payment Date is required before saving.');
				ApexPages.addMessage(myMsg);
				return false;
			}
			Customer_Payment__c[] paymentsToInsert = new List<Customer_Payment__c> ();
			Customer_Payment_Apply__c[] applicationsToInsert = new List<Customer_Payment_Apply__c> ();

			for (Invoice_Split__c split : invoice.Invoice_Splits__r) {
				system.debug(split);
				Customer_Payment__c splitPayment = new Customer_Payment__c();
				splitPayment.NACHA_File__c = nf.Id;
				splitPayment.Amount__c = split.Invoice_Split_Amount__c;
				splitPayment.Customer_Id__c = NewPayment.Customer_Id__c;
				splitPayment.Tran_Date__c = NewPayment.Tran_Date__c;
				splitPayment.Default_Vendor_Payment_Date__c = NewPayment.Default_Vendor_Payment_Date__c;
				splitPayment.AR_Account_Id__c = NewPayment.AR_Account_Id__c;
				splitPayment.Payment_Type__c = NewPayment.Payment_Type__c;
				splitPayment.GL_Account_Id__c = NewPayment.GL_Account_Id__c;
				splitPayment.Payment_Division_Id__c = NewPayment.Payment_Division_Id__c;
				splitPayment.Coverage_Month__c = NewPayment.Coverage_Month__c;
				splitPayment.Location__c = NewPayment.Location__c;
				splitPayment.Memo__c = NewPayment.Memo__c;
				splitPayment.Posting_Period__c = NewPayment.Posting_Period__c;
				splitPayment.Batch__c = NewPayment.Batch__c;
				splitPayment.COL_Code__c = NewPayment.COL_Code__c;
				paymentsToInsert.add(splitPayment);

			}
			insert paymentsToInsert;
			for (Customer_Payment__c pmt : paymentsToInsert) {
				Customer_Payment_Apply__c application = new Customer_Payment_Apply__c();
				application.Customer_Payment_Id__c = pmt.Id;
				application.Invoice_Id__c = invoice.Id;
				application.Amount__c = pmt.Amount__c;
				applicationsToInsert.add(application);

			}
			insert applicationsToInsert;
			return true;
		}
	}

	// Incoming NACHA
	public PageReference cancelToInvoice() {
		PageReference pageReference = new PageReference('/' + key);
		pageReference.setRedirect(true);
		return pageReference;
	}


	/////////////////////////////////////////////////////////////////
	// Both Regular NACHA and Incoming NACHA
	/////////////////////////////////////////////////////////////////
	private void InitializeDefaults() {
		key = ApexPages.currentPage().getParameters().get('invoiceid');

		nachaDefaultNames = new List<SelectOption> ();
		nachaDefaults = new Map<String, CS_Nacha_Defaults__c> ();

		// Need to order by Ordinal__c so I went with the direct SOQL route instead of the cached call (getAll)
		for (CS_Nacha_Defaults__c nd :[SELECT Name, Immediate_Origin__c, Immediate_Origin_Name__c, Immediate_Destination__c, Destination_Name__c,
		     Company_Name__c, Company_Id__c, Originating_DFI_Id__c, Company_Entry_Description__c
		     FROM CS_Nacha_Defaults__c
		     WHERE Active__c = true
		     ORDER BY Ordinal__c DESC]) {
			nachaDefaultNames.add(new SelectOption(nd.Name, nd.Name));
			nachaDefaults.put(nd.Name, nd);
		}

		selectedNachaDefaultName = nachaDefaultNames[0].getValue();
		setDefaults();

	}


	public void setDefaults() {

		CS_Nacha_Defaults__c selectedNachaDefault = nachaDefaults.get(selectedNachaDefaultName);
		//headerImmediateDestination = '011900254'; 
		//headerImmediateOrigin = '1200645984'; 
		//headerDestinationName = 'BANK OF AMERICA'; 
		//headerImmediateOriginName = 'PLANSOURCE BEN ADMIN'; 
		//batchCompanyName = 'PLANSOURCE'; 
		//batchCompanyId = '1550800751'; 
		//batchOriginatingDfiID = '011900254'; 
		headerImmediateDestination = selectedNachaDefault.Immediate_Destination__c;
		headerImmediateOrigin = selectedNachaDefault.Immediate_Origin__c;
		headerDestinationName = selectedNachaDefault.Destination_Name__c;
		headerImmediateOriginName = selectedNachaDefault.Immediate_Origin_Name__c;
		batchCompanyName = selectedNachaDefault.Company_Name__c;
		batchCompanyId = selectedNachaDefault.Company_Id__c;
		batchOriginatingDfiID = selectedNachaDefault.Originating_DFI_Id__c;
		batchCompanyEntryDescription = selectedNachaDefault.Company_Entry_Description__c;
	}

}
Hello,
While validating Dashboard, I am getting error:
Must specify sortBy attribute to one dashboard table column.

How to Resolve the above error. I have checked with all the reports ascociated with dashboards for which above error is coming. There is already Sort by attribute in Report. 
I have junction object "Author-Research Paper". This object has two master detail relationship with objects "Authors" and "Research Paper".
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it? 
Hello All,
There is a custom metadata with four fields AreaCode,ZipCode,State and TimeZone. Whenever these field values are inserted/updated, TimeZone value need to be update. How to achieve this fucntionality through configuration or Lightning Flows?
Please suggest.

Hello Folks,
There are two System Admin in my Dev Org. Whenever, I will create new Contact record, it must be assigned to another System Admin and Whenever Other System Admin will create Contact Record, it should be assigned to me. (Round Robin)

Here AssignedTo__c is a custom field with Lookup Relation data type(User).

 

Please suggest.

Hello Folks,
How to write Handler for below trigger.?

trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete, After Undelete) {
 List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
    if(Trigger.isInsert){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
			}
		}
    } 
    system.debug('setAccIds ==> '+setAccIds);
    if(Trigger.isUpdate){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){ 
            if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && con.Amount>10000.00){
               	setAccIds.add(con.AccountId);
                setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
            	}
            
			}        
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.old) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    
    if(Trigger.isUndelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.new) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    for(Account acc :[Select id,Total_Opportunity__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : setAccIds]){
			
        acc.Total_Opportunity__c = acc.Opportunities.size();
        acclist.add(acc);
        
    }
    if(acclist.size()>0){
        update accList;     
    }
    
}

Hello Folks, 

I am new to salesforce development. Attempting to write a test class for below code. Please suggest.
 

public class CountContactHandler {
    
    public static void ContactCheckBox(List<Contact> con) {
        
        Set<Id> setid = new Set<Id>();
        for(Contact c : con) {
            setid.add(c.AccountId);
        }
        
        List<Account> acc1 = [SELECT Id, Name From Account WHERE Id In :setid];
        
        for(Account a1 : acc1) {
            
        }
    }

}

Hello Community,

In my VF page, I want to show/Hide Custom setting Component based on User Login. Is it possible through Configuration or else It requires codig?

Marked text is a link that derives from custom setting. Please suggest solution.User-added image

Hi,
In my org, there are two objects Case and Project. Case object is having lookup relation with Project and Account Object. Now whenever, Case record is cretaed for particular Project, its asscoiated Account should get populated in case record. Plz help to write trigger for same.
public class StatusPublished implements database.Batchable<sobject>,Schedulable{

    public void execute(Schedulablecontext sc)
    {
         string cron='0 2 * * * ?*';
        StatusPublished sp =new StatusPublished();
        system.schedule('updatepaper', cron, sp);
      //database.executeBatch(sp);
    }
        public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select id,Name,Status__c from Research_Paper__c';
        return database.getQueryLocator(query);
    }
        public void execute(database.BatchableContext bc,list<Account> acc)
    {
        List<Research_Paper__c> rlist=new list<Research_Paper__c>();
        for(Research_Paper__c rp: rlist)
        {
            if(rp.Status__c=='Paper registration Complete')
            {
                rp.Status__c='Published';
                rlist.add(rp);
            }
        }
        update rlist;
    }
    
     public void finish(database.BatchableContext bc)
    {
 
    }

 
I am writing this trigger to prevent duplicate entry. But this trigger runs even at time of creating new record..How to resolve?
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId) && acmap.get(opp.AccountId).Opportunities!=null)
        {
        
           {
               if(opp.StageName=='Prospecting')
               {
                     (opp.AccountId).addError('Duplicate value');
               }
           }
        }
    }
}
Scenario for trigger is that, if Opportunity Object having record with field stageName=='Prospecting ' and Parent Account name with,lets say XYZ.,so another record with same field value and same parent should not get duplicated.. I have written below trigger but it is showing error.

 
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId))
        {
           if(acmap.get(opp.AccountId).StageName=='Prospecting')
           {
               (opp.AccountId).addError('Duplicate value');
           }
        }
    }
}
I want to remove prefix 'Mr.' from my Account object. I have tried through the BatchApex class. But still its not working.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(account a:alist)
        {
           a.name= a.Name.removeStart('Mr.');
        }
        
        update alist;
        system.debug(alist);
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}
 
I have junction object "Author-Research Paper". This object has two master detail relationship with objects "Authors" and "Research Paper".
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?