Thursday, April 20, 2023

How To Send Set of Ids or Set of Records From Lwc Component To Apex Method

If you're planning to use the set as the one of the parameter of your apex function and the same need to passed from lwc js look at these limitations below.

  • By default @AuraEnabled methods will not accept /allow to use the set of Records as the parameter. 
  • In detail, it's not only support set of Records even if you try to pass of set of Ids, set of strings and set of Records it will not work because it's doesn't support set data type it self.
The work around for this is 

  • The @AuraEnabled method again will support the list as a parameter so you either convert parameter from set to list is one option.
  • You can also try out the convert the set of Records into string in lwc using the Json.stringify() and change the your apex method param to string and inside method you can deserialize the string to set in side the apex method. 

Tuesday, April 18, 2023

Not exported by package compiler Unexported Name Error in Go Language

In Go language the functions can be exported with help of the keyword called "package" and same can be reused by importing in other classes with help of  key word called "import".

Even after making the function available to be used in other classes if your receiving the error called "not exported by package " please check if the below solution works for you.

The first letter of the function should be capital letter otherwise even you exported you can't find this function when you try to reference in other classes. So make sure that if any method that you want to re-used please declare with Capital letters.

firstClass.go
=======================================
package connectors

import (
 "fmt",
 "time"
 )
 
 func isNewToGoLang(string mobile) (isnew bool){
 
  if mobile == nil
    return false
  else
    return true
 }
 
 
secondClass.go
==================================
import (
  fclass "/connectors"
)

func checkAccess(){
  resp =: fclass.isNewToGoLang("1234")
  
}

Here I'm trying to access the method called isNewToGoLang() which is delcared in firstClass.go in secondClass.go ,even though i have exported the function still i'm getting an error because the first character of the method is small letter so it will not work.

As mentioned above if i update the method name with capital letter it will work as expected.


firstClass.go
--------------------------------------
package connectors

import (
 "fmt",
 "time"
 )
 
 func IsNewToGoLang(string mobile) (isnew bool){
 
  if mobile == nil
    return false
  else
    return true
 }
 
 
secondClass.go
------------------------------------
import (
  fclass "/connectors"
)

func checkAccess(){
  resp =: fclass.IsNewToGoLang("1234")
  
}

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

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


FaceBook Page - I Love Coding. You?


Hope this helps you..Enjoy..!

Monday, April 17, 2023

How Convert Pointer *bool to bool or *string to string in go lang functions

Most of the use cases in any technology the functions will be returning the some response either in string ,bool,float,int or some custom struct format. This is the basis use case in our regular programming.

Similarly in Go language if your writing any simple functions will return the same data types mentioned above or sometimes as pointer reference also will be returned.

In case if function returning the pointer reference how to converted the same pointer reference to it's underlying data type will be discussed in this post. If we are not converting we will be receiving the error as  "cannot use yourvariableName (variable of type *bool/string/int) as bool/string/int value in assignment compilerIncompatibleAssign "

Example : Pointer bool to bool or pointer string to string

package main

import "fmt"

func main() {
	var resp *bool
	resp = isNewToGoLang("8888888888")
	var isNewVar bool
	if resp != nil {
		isNewVar = *resp
		fmt.Println("Is New Var ", isNewVar)
	}
}

func isNewToGoLang(mobile any) *bool {

	varFalse := false
	varTrue := true
	if mobile == nil {
		return nil
	}
	if mobile != nil {
		return &varTrue
	}
	return &varFalse
}

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

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


FaceBook Page - I Love Coding. You?


Hope this helps you..Enjoy..!