function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
May_The_ForceMay_The_Force 

Custom Button/Link Related Question

Hello. I am new to SF development and currently at a standstill in attempting to validate an e-mail address.

 

I have an object called Users which has accepts a name and e-mail address (both text on a standard SF page). I have also created a custom link called "validate e-mail". I plan to call a webservice passing the user-entered e-mail address when the custom link is clicked.I have imported my WSDL into an APEX class and everything works (I tested also)

 

Currently, I am not able to figure out how to display the user-entered value when the link is clicked.

 

Upon clicking on my link, I just want to display the user entered value in an alert statement but I have been unsuccessful. If this works I would like to call my webservice class and validate the e-mail address upon clicking on my custom link
.

I have been reading the forums and cookbook, but still not able to figure it out. Any help is appreciated...Thanks.

Pradeep_NavatarPradeep_Navatar

Use standardcontroller = "Users__c" and get the id from :

 

Id uid = Apexpages.currentPage().getParameters().get('id');

 

after that use SOQL Query to get email address and name :

 

Users__c usr=[select id, name,email from Users__C where id =:uid];

 

Hope this helps.

 

 

May_The_ForceMay_The_Force

Thank you for your reply.  I am still struggling to get the user-entered value. Essentially this is what I am trying to do:

 

  1. I have set up an object called Users (API name MovieAppUser__c) with two fields one a user name and another a custom field called e-mail (which is of the type text). I am able to enter records through a standard sales force page (my Users tab).
  2. What I would like to do is whenever a new user is being inserted I would like to fire off a trigger that validates the e-mail address via a web service call
  3. I have created the APEX Class by importing the WSDL and tested it out (it works)
  4. I have created the public class which makes the call to the webservice
  5. I have created the APEX Trigger (on the Users) on my Users object which fires off before insert , to ensure user has entered a correct e-mail address

 

In short, my goal is to validate an e-mail id that the user enters via a webservice (I just want to try it for the sake of trying and learning APEX and cloud computing). Perhaps In hindsight, I should have picked something simper to begin with…

 

I get the following error:

 

"Apex trigger webserviceTrigger caused an unexpected exception, contact your administrator: webserviceTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.webserviceTrigger: line 10, column 15"

 

After some research, I noticed that webservice callouts are not allowed via triggers. I tried some alternate approaches:

 

Option 1  - Let the javascript on the standard SF page call the class which calls the webservice to validate the e-mail ID before saving the record

--------------------------------------------------------------------------------------------------------------------------------------------------

 

I created a custom link which upon clicking validates my e-mail ID but I am still not able to get the user-entered value from the web page to the javascript. I can't figure out the name or id of the e-mail textbox from the webpage. The API name for the custom e-mail field is e_mail__c, but when I try this it's not working. How can I get the ID of the field?

 

 

Option 2 - Creating a new Visual Force Page

--------------------------------------------------------------------------------------------------------------------------------------------------

 

Some community folks have also suggested the use of a Custom VisualForce page that is pretty much like a form. When submitting the form, call javascript which calls the class containing web service calls....again I'm running into the same issues.

 

My Form:

<apex:page standardController="MovieAppUser__c">

<apex:form >

<apex:pageBlock title="My Content" mode="edit">

<apex:pageBlockButtons >

<apex:commandButton action="{!save}" value="Save"/>

</apex:pageBlockButtons>

<apex:pageBlockSection title="My Content Section" columns="2">

<apex:inputField value="{!MovieAppUser__c.name}"/>

<apex:inputField value="{!MovieAppUser__c.e_mail__c}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

My Class :

global class My_Class {



    public static Boolean checkValidEmail( String p_email  ){

        boolean m_flag ;

        validateEmailwwwWebservicexNet.ValidateEmailSoap m_myVar = new  validateEmailwwwWebservicexNet.ValidateEmailSoap();

        

        try{

            m_flag = m_myVar.IsValidEmail( p_email ); 

            

            system.debug (' -------------> My webservice call value =' + m_flag );

        }catch(Exception e ){

            system.debug (' -------------> Exception occured in the web service call' );

            e.getMessage();

        }

        

        return m_flag ;       

    }

}

What is the best way to achieve my goal? How should my Javascript be? I just need to get an idea....

 

Thanks.