Thursday, July 18, 2024

Look up fields in Salesforce Flow Datatable

How to fetch lookup fields on flow datatable in Salesforce Flows.


Think before you get the solution, this is what one of my colleague(Hans) said to me. Since I am in a complete programming mind set, could not check well what is provided in the configurations of a screen flow.

But if you think slowly and relate every single line and variable assignments of a program, you can do the same thing in flow.


Step1 : Fetching records

Using Get Records, you can fetch all the records (as you all were aware).


Step 2: Looping the records ( the main task)

Step 2.1 : After creating the loop, create a Variable resource ( remember not a collection). It should be the same as the collection record type (i.e..., the records object for what you fetched in the Step 1)

                    Lets name the variable as "individual_variable" in this example.

Step 2.2 : In the looping, Use the individual_variable in the loop and Assign the current Item that is looping.

Step 2.3 : Click on Add assignment button. There select the Lookup object's field Id from the "individual_variable"  and in the value select the Name field of "Current Item from loop"

Step 2.4 : For every variable you want to show it on the data table you assign it to the "individual_variable

Step 2.5 : Create a New Resource, of the same object type and this time it will be the collection.

      "Allows multiple values"  For Example we can name it as (collection_after_iteration)

Step 2.6 : Add the "individual_variable" to the collection we just created.


Step 3 : Pass the collection (collection_after_iteration) to the data table. 

That's all folks, it will be bit tricky to think, but the credit of explaining this to me goes to The Master Johannes (Hans). There is a need to correct some blogs and documentations




Sunday, November 26, 2017

Generating Java Class files from salesforce wsdl using Apache Axis and sforce.ws.tools and command prompt - salesforce/ webserevice login url


Hi,

I am mentioning the source code to generate the .class files from wsdl using Apache Axis jar files.
I am using the salesforce wsdl file. Creating the class files procedure will not change for other wsdl files when using apache axis.

There are two ways to generate the .class files one is using apache axis and other is using the sforce.ws.tools.


I . Generate java .class files using apache axis.

  • Jar files required 
    • axis.jar;
    • axis-ant.jar;
    • commons-discovery-0.2.jar;
    • commons-logging-1.0.4.jar;
    • dsn.jar;
    • imap.jar;
    • jaxrpc.jar;
    • log4j-1.2.8.jar;
    • mailapi.jar;
    • pop3.jar;
    • saaj.jar;
    • smtp.jar;
    • wsdl4j-1.5.1.jar
You can use the latest mentioned .jar files as per the latest versions available.

2. Save all the jar files in the folder location where you want to generate the .class files and set the classpath of the jar files in the environment variables.

3. Save the wsdl file from salesforce API ( you can select partner/enterprise based on requirement).

4.  open the cmd prompt and change the directory where the .jar files are located.

5. execute the below command

 java -classpath axis.jar;axis-ant.jar;commons-discovery-0.2.jar;commons-logging-1.0.4.jar;dsn.jar;imap.jar;jaxrpc.jar;log4j-1.2.8.jar;mailapi.jar;pop3.jar;saaj.jar;smtp.jar;wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java -a enterprise.wsdl.

Please comment if you are getting any error messages in the procedure.

I have compiled this using java 1.8 version.

Sunday, July 30, 2017

How to get RecordType name of an object Salesforce


How to get RecordTypeName of an object in Salesforce.




Step 1:
Declare this like initialization parameter before any loop

Map<ID, Schema.RecordTypeInfo> recordTypeMap = Schema.SObjectType.Case.getRecordTypeInfosById();


Change the object accordingly.


Step 2 : 

Get the  Record type as String like below.

String recordtypeName =  recordTypeMap.get(case.RecordTypeId).getName(); 


Full Example :

class { 

List<Case> caseList = [Select id, name,status from case limit 100];

    List<Case> toUpdate = new List<Case>();

Map<ID, Schema.RecordTypeInfo> recordTypeMap = Schema.SObjectType.Case.getRecordTypeInfosById();
   
    for (Case c : caseList){
        if(
recordTypeMap.get(c.RecordTypeId).getName()  ==  '*******'){
            case cxUpdate = new Case();
            cxUpdate.id = c.id;
            cxUpdate.status = 'In Support';
            toUpdate.add(cxUpdate);
        }
        update toUpdate;   
    }

 

}
 



 

Saturday, June 11, 2011

Rss Feeds to XML using database values

main class to create XML file.

Jar files required : commons-digester-rss.jar,  mysql-connector-java-5.0.8.jar

package sri;

import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.digester.rss.Channel;
import org.apache.commons.digester.rss.Item;

public class RssFeeds
{

    public void RssXml() throws Exception{
  
    RssImpl rImpl = new RssImpl();
    RssBean rBean = new RssBean();
  
    String title = "ItemTitle1";
  
    rBean = rImpl.getRssData(title);
  
    Channel newChannel = new Channel();

    newChannel.setCopyright(rBean.getCpyRight());
    newChannel.setDescription(rBean.getDesc());
    newChannel.setLink(rBean.getChannLink());
    newChannel.setLanguage(rBean.getLang());
    SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss Z");
    String today = formatter.format(rBean.getPubDate());
    newChannel.setPubDate(today);

    Item item = new Item();
    item.setTitle(rBean.getItemTitle());
    item.setLink(rBean.getItemLink());
    item.setDescription(rBean.getItemDesc());
    newChannel.setPubDate(today);
    newChannel.addItem(item);

    try
    {
        FileOutputStream fout = new FileOutputStream("C:/feed.xml");
        newChannel.render(fout);
        fout.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    }
  
    public static void main(String args[]) throws Exception {
    RssFeeds rss = new RssFeeds();
    rss.RssXml();
    }
}



using hibernates to access data from database.

package sri;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class RssImpl
{
    Session session = null;

    public RssBean getRssData(String title)throws Exception
    {
    session = HibernateUtil.currentSession();

    RssBean rssBean = new RssBean();
    Criteria crit = session.createCriteria(RssBean.class);
    crit.add(Restrictions.eq("itemTitle", title));
    if(crit.list().size()>0)
        rssBean = (RssBean) crit.list().get(0);
   
    /*String hql = "FROM RssBean as rBean WHERE rbean.itemTitle ='"+ title +"'";
    Query query = session.createQuery(hql);
    if(query.list().size()>0)
        rssBean = (RssBean) query.list().get(0);*/

    return rssBean;

    }

}


create a bean class:

package sri;

import java.io.Serializable;
import java.sql.Timestamp;

public class RssBean implements Serializable{
   
    private String cpyRight;
        private String itemTitle;
    private String desc;
    private String channLink;
    private String lang;
    private Timestamp pubDate;
    private String itemLink;
    private String itemDesc;
   
    public String getCpyRight()
    {
        return cpyRight;
    }
    public void setCpyRight(String cpyRight)
    {
        this.cpyRight = cpyRight;
    }
    public String getItemTitle()
    {
        return itemTitle;
    }
    public void setItemTitle(String itemTitle)
    {
        this.itemTitle = itemTitle;
    }
    public String getDesc()
    {
        return desc;
    }
    public void setDesc(String desc)
    {
        this.desc = desc;
    }
    public String getChannLink()
    {
        return channLink;
    }
    public void setChannLink(String channLink)
    {
        this.channLink = channLink;
    }
    public String getLang()
    {
        return lang;
    }
    public void setLang(String lang)
    {
        this.lang = lang;
    }
    public Timestamp getPubDate()
    {
        return pubDate;
    }
    public void setPubDate(Timestamp pubDate)
    {
        this.pubDate = pubDate;
    }
    public String getItemLink()
    {
        return itemLink;
    }
    public void setItemLink(String itemLink)
    {
        this.itemLink = itemLink;
    }
    public String getItemDesc()
    {
        return itemDesc;
    }
    public void setItemDesc(String itemDesc)
    {
        this.itemDesc = itemDesc;
    }
}

Hibernate util: save as Hibernateutil.java

package sri;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;


public class HibernateUtil {

    private static SessionFactory sessionFactory;
    private static String schema;

    static {
    try {
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        sessionFactory = configuration.buildSessionFactory();
        SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) sessionFactory;
        schema = sessionImpl.getSettings().getDefaultSchemaName();
    } catch (Throwable ex) {
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
    }

    private static final ThreadLocal<Session> localSession = new ThreadLocal<Session>();

    /**
     * Create CurrentSession when session not open
     */
    public static Session currentSession() {
    Session s = (Session) localSession.get();

    if (s == null) {
        s = createSession();
    }

    if (!s.isOpen() || !s.isConnected()) {
        localSession.set(null);
        s = null;
        s = createSession();
    }

    if(s.isDirty()){
        if(s.getTransaction().isActive())
        s.getTransaction().rollback();
        s.flush();
        s.close();
        s = null;
        localSession.set(null);
        s = createSession();
    }
    return s;
    }

    /**
     * Create Session
     * @return Session
     */
    private static Session createSession() {
    Session s = sessionFactory.openSession();
    localSession.set(s);
    return s;
    }

    /**
     * Close Session
     * @throws HibernateException
     */
    public static void closeSession() throws HibernateException {
    Session session = localSession.get();
    if (session != null && session.isOpen()) {
        if(session.getTransaction().isActive()) {
        session.getTransaction().rollback();
        }
        session.close();
        localSession.set(null);
    }
    }

    /**
     * Fetch the SessionFactory
     */
    public static SessionFactory getSessionFactory() {
    return sessionFactory;
    }

    /**
     * Flush the Session
     * @throws HibernateException
     */
    public static void flushSession() throws HibernateException {
    Session session = localSession.get();
    if (session != null) {
        session.flush();
    }
    }

    /**
     * Close SessionFactory
     */
    public static void shutdown() {
    getSessionFactory().close();
    }

    /**
     * Save or Update the object and close the session
     */
    public static Object saveOrUpdate(Object obj) {

    Session session = null;
    try {
        session = HibernateUtil.currentSession();
        Transaction transaction = session.beginTransaction();
        transaction.begin();
        session.saveOrUpdate(obj);
        transaction.commit();
        closeSession();
    }catch(HibernateException ex) {
    }
    return obj;
    }

    /**
     * Fetch the Schema
     */
    public static String getDefaultSchema() {
    return schema;
    }

}

hbm.xml file to map the data from the database:: save as -- RssBean.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="sri.RssBean" table="rssfeeddata">
        <id column="TITLE" name="itemTitle" type="java.lang.String">
        </id>
        <property column="COPYRIGHT" name="cpyRight" type="java.lang.String"/>
        <property column="DESCRIPTION" name="desc" type="java.lang.String"/>   
        <property column="CHANNELLINK" name="channLink" type="java.lang.String"/>
        <property column="LANGUAG" name="lang" type="java.lang.String"/>
        <property column="PUBDATE" name="pubDate" type="java.sql.Timestamp"/>
        <property column="ITEMLINK" name="itemLink" type="java.lang.String"/>
        <property column="ITEMDESCRIPTION" name="itemDesc" type="java.lang.String"/>
    </class>
</hibernate-mapping>

Hibernate configuration file save as : hibernate.cfg.xml


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/sri</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <!-- Mapping files -->
        <mapping resource="hbm/RssBean.hbm.xml" />
    </session-factory>
</hibernate-configuration>

Convert pdf to text file using PDFBox

import java.io.File;
import java.io.PrintWriter;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.util.PDFStreamEngine;
import org.pdfbox.util.PDFTextStripper;


public class PDFText extends PDFStreamEngine
{

    public static void main(String[] args)
    {
    PDDocument pd;
    String parsedText = null;
    try
    {
        File input = new File("D:\\Head First Servlets and JSP, Second Edition.pdf");
        File output = new File("C:\\SampleTex.txt");
        pd = PDDocument.load(input);
        System.out.println(pd.getNumberOfPages());
        System.out.println(pd.isEncrypted());
        pd.save("C:\\Copy_of_main.pdf");
        PDFTextStripper stripper = new PDFTextStripper();
        stripper.setStartPage(1);
        stripper.setEndPage(100);
        parsedText = stripper.getText(pd);
        System.out.println(parsedText);
        String st = stripper.getText(pd);
        PrintWriter pw = new PrintWriter(output);
        pw.print(st);
        pw.close();

        if (pd != null)
        {
        pd.close();
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    }
}


Required jar files : fontbox-0.1.0.jar, pdfbox-0.7.3.jar, pdfbox-0.8.0-incubating.jar (add this jar file as a option)

Look up fields in Salesforce Flow Datatable

How to fetch lookup fields on flow datatable in Salesforce Flows. Think before you get the solution, this is what one of my colleague(Hans) ...