Sunday, May 29, 2022

Aura:if isTrue issue in salesforce

If you're facing an issue with Aura:if isTrue while using the And Clause or OR clause we need to know the below points.

According to salesforce documentation And/Or clause only supports two arguments for evaluation.

If you're using more than 2 arguments in And/Or clause by default Salesforce ignores it.


<Aura:if IsTrue ="Or(expression 1,expression 2)">   - - This is valid.

<Aura:if IsTrue ="Or(expression 1,expression 2, expression 3)"> - - This will not work as expected because Salesforce ignores the expression 3 for evaluation. 


Workaround :

If you need to solve this problem simply convert them into simple multiple chain expressions. 

Aura:if IsTrue ="Or(expression 1,expression 2) || expression 3)"> 

Aura:if IsTrue ="Or(expression 1,expression 2) || Or(expression 3, expression 4)"> 


Hope this helps you..Enjoy..!


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.























Friday, May 27, 2022

How to Link a Child Record Every Time it's Created With An Existing/New Parent Record.

Lets take a use case when a child record has been created it should be automatically link to existing parent record ,in case if parent is not available it should create a parent and link the child record automatically.

The relationship between these objects is "Lookup Relationship" and the identifier to map the child with parent and the identifier when to create a new parent will be discussed below.

Simple use case here is we will have daily time sheet entries of an employee and all these daily time sheet entries should get linked under weekly time sheet entry which is like one entry for one week with 7 daily time sheet under same parent.

We can assume child object as "Daily_Time_Sheet__c" and parent object as "Weekly_Time_Sheet__c". On parent object we will have one field with name as "Parent_User_Week_Start__c(which is an external id) " which is the combination of user id and start date of the week of a given date in "Daily_Time_Sheet__c".The field name in child would be something like "ChildUserIdWeekStrartDate__c".

Source Code:

Trigger DailyTimeSheetTrigger On Daily_Time_Sheet__c(after insert)
{
	List<Weekly_Time_Sheet__c> listWTSToUpsert = new List<Weekly_Time_Sheet__c>();
	List<Daily_Time_Sheet__c> listDTSUpdate = new List<Daily_Time_Sheet__c >();
	Map<String,id> mapHours = new Map<String,id>();
	set<string> setUniqueParent = new set<string>();

	for(Daily_Time_Sheet__c dts:Trigger.new)
	{
		if(dts.ChildUserIdWeekStrartDate__c!=null && dts.Weekly_Time_Sheet__c==null)
		{
			Weekly_Time_Sheet__c wts = new Weekly_Time_Sheet__c();
			wts.Parent_User_Week_Start__c = dts.Chi;
			if(!setUniqueParent.contains(wts.Parent_User_Week_Start__c))
			{
			  listWTSToUpsert.add(wts);
			  setUniqueParent.add(wts.Parent_User_Week_Start__c);
			}
		}
	}
	
	try
	{
		if(!listWTSToUpsert.isEmpty())
		  Database.UpsertResult[] wtsUpsertResult = Database.upsert(listWTSToUpsert,Weekly_Time_Sheet__c.Parent_User_Week_Start__c,false);
	  
		for(Weekly_Time_Sheet__c ws:listWTSToUpsert)
		{
			mapHours.put(ws.Parent_User_Week_Start__c,ws.id);
		}


		for(Daily_Time_Sheet__c dts:[SeLEcT id ,ChildUserIdWeekStrartDate__c,Weekly_Time_Sheet__c FROM Daily_Time_Sheet__c WHERE ID IN: Trigger.new])
		{
			if(dts.ChildUserIdWeekStrartDate__c!=null && dts.Weekly_Time_Sheet__c==null)
			{
				if(mapHours.containsKey(bh.ChildUserIdWeekStrartDate__c))
				{
					bh.Weekly_Time_Sheet__c = mapHours.get(guid);
					listDTSUpdate.add(bh);
				}
			}
		}
		
		if(!listDTSUpdate.isEmpty())
			Database.SaveResult[] wbhUpsertResult2 = Database.update(listDTSUpdate,false);
	}
	catch(exception e)
	{
		system.debug('exception ..'+e);
	}
}

Hope this helps you..Enjoy..!


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.






Wednesday, May 25, 2022

Convert Date into Long Time String in Salesforce Apex

  • First convert the date feild into the datetime field format
  • The getTime() in the datetime class will returns the number of milliseconds of a given date starting from  January 1, 1970, 00:00:00 GMT.

Source Code:

Date todayDate = Date.today();
DateTime todayDateTime = DateTime.newInstance(todayDate.year(),todayDate.month(),todayDate.day());
string longTime =String.valueOf(todayDateTime.getTime());
System.debug('Date in long time string..'+logTime);



Hope this helps you..Enjoy..!


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.








How to get the start date of the week for the given date in Salesforce

 If your trying to know the starting date of the week for the given date in salesforce please use the below 2 formats.


Using the Formula Fields:

The return type of the formula is date.

(Yourdatefield__c- MOD(Yourdatefield__c- DATE(1900, 1, 7), 7))

Using the Apex:

In case of apex we can use the salesforce in built date function called toStartofWeek() which returns the start date of week basis on the user locale.

  • Sunday will be treated as US locale
  • Monday in case of European locale

Date startWeek = Yourdatefield__c.toStartofWeek();

In my case given date is 20th Friday and start of the week will returns as 15th on Sunday


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Tuesday, May 24, 2022

Salesforce Data Loader Log4j Vulnerability or Data Loader Installation Issues

Salesforce Data loader is a tool which will be used to insert, update, delete, export and hard delete salesforce objects data. As we know in recent times Log4j vulnerability caused a lot of issues on multiple systems.

Basically to run the data loader we must have JDK setup on your systems so a part of the this vulnerability data loader has started facing some issues. So, Salesforce has suggested to delete the existing data loader and to set up this again after downloading the latest version from salesforce setup which is not have these issues. 

While setting up this i have come across some of the java/jdk related issues and it's been sorted out with the help of the articles mentioned below. If anyone of facing same issue related to java/jdk setup you can refer the below posts for step by step process.

How to Install Azul Zulu OpenJDK Version 11 on Windows for data loader?

Install Azul Zulu on Windows


Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!


 

Thursday, May 19, 2022

RecordType Translations Are Not Working in Salesforce

 In case of these scenarios please cross check the below things.

  • Whether logged in user county and language are properly settled or not.
  • Whether translations are mapped correctly for the logged in user language or not.
  • Check whether record type name and record type api name both are same or not.
  • If both are not same and if the data comes from the SOQL please try to use the toLabel(RecordType.Name) in SOQL. Whenever we are making a query returns the api name instated of record type label so the translations might break.

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!