• Davide Gammone
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Salesforce Technical Manager
  • Atos


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 8
    Replies
How to construct a security WSSE header in APEX code to make a SOAP call out?
This is the XML that I am trying to reproduce. 
<soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
</soapenv:Header>

SOAP object class (WSDL2Apex):
... 
public class Soap {
        public SFMC_SOAP_TO_SF_SECURITY.SecurityHeader securityHeader = new SFMC_SOAP_TO_SF_SECURITY.SecurityHeader('USERNAME', 'PASSWORD');
        private String Security_hns = 'Security=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
        public String endpoint_x = 'HIDDEN FOR PRIVACY';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://exacttarget.com/wsdl/partnerAPI', 'SFMC_SOAP_TO_SF_API'};
        public SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element VersionInfo(Boolean IncludeVersionHistory) {
            SFMC_SOAP_TO_SF_API.VersionInfoRequestMsg_element request_x = new SFMC_SOAP_TO_SF_API.VersionInfoRequestMsg_element();
            request_x.IncludeVersionHistory = IncludeVersionHistory;
            SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element response_x;
            Map<String, SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element> response_map_x = new Map<String, SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'VersionInfo',
              'http://exacttarget.com/wsdl/partnerAPI',
              'VersionInfoRequestMsg',
              'http://exacttarget.com/wsdl/partnerAPI',
              'VersionInfoResponseMsg',
              'SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
public SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element Retrieve_x(SFMC_SOAP_TO_SF_API.RetrieveRequest RetrieveRequest) {
            SFMC_SOAP_TO_SF_API.RetrieveRequestMsg_element request_x = new SFMC_SOAP_TO_SF_API.RetrieveRequestMsg_element();
            request_x.RetrieveRequest = RetrieveRequest;
            SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element response_x;
            Map<String, SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element> response_map_x = new Map<String, SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'Retrieve',
              'http://exacttarget.com/wsdl/partnerAPI',
              'RetrieveRequestMsg',
              'http://exacttarget.com/wsdl/partnerAPI',
              'RetrieveResponseMsg',
              'SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
}
...

Security Header class
public class SFMC_SOAP_TO_SF_SECURITY 
{

    public class UsernameToken {
        // Constructor for UsernameToken used to pass in username and password parameters
        public UsernameToken(String username, String password)
        {
            this.Username = username;
            this.Password = new password_e(password);
        }

        public String Username;
        public password_e Password;
        private String[] Username_type_info = new String[]{'Username','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Password_type_info = new String[]{'Password','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
        private String[] field_order_type_info = new String[]{'Username','Password'};

    }
    
        public class password_e{
            public password_e(String password) {
                this.password = password;
                type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';             
    	}

            public String password;
            public string type; 
            public String[] type_att_info = new String[]{'Type'};        
            private String[] password_type_info = new String[]{'Password','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText','string','1','1','false'};
            private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
            private String[] field_order_type_info = new String[]{'password'};
    }

    
    
    // SecurityHeaderType Class
    public class SecurityHeaderType 
    {       
        // Constructor for SecurityHeaderType used to pass in username and password parameters and instantiate the UsernameToken object     
        public SecurityHeaderType(String username, String password)
        {
            this.UsernameToken = new SFMC_SOAP_TO_SF_SECURITY.UsernameToken(username, password);
        }

        public String wsuNamespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';              
        public SFMC_SOAP_TO_SF_SECURITY.UsernameToken UsernameToken;
        private String[] UsernameToken_type_info = new String[]{'UsernameToken','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','UsernameToken','1','1','false'};
        private String[] wsuNamespace_att_info = new String[]{'xmlns:wsu'};               
        private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
        private String[] field_order_type_info = new String[]{'UsernameToken'};
    }
    

    public class SecurityHeader{
        
        public SecurityHeader(String username, String password){
            this.headerPackager = new SFMC_SOAP_TO_SF_SECURITY.SecurityHeaderType(username, password);
        }
    
        public String wsseNamespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
        public SFMC_SOAP_TO_SF_SECURITY.SecurityHeaderType headerPackager;
		private String[] wsseNamespace_att_info = new String[]{'xmlns:wsse'};               
		private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
		private String[] field_order_type_info = new String[]{'Security'}; 
        
    }
}



 
Hi,
  
   I want to display the week number based  on quartrly of the year Please suggest me how to display
 
   Below is the image how it should be displayed
   User-added image

I wrote a formula which is giving quarter correctly but the week number is not displayed correclty
CASE(MONTH( CloseDate ),1,"Q4",2,"Q1",3,"Q1",4,"Q1",5,"Q2",6,"Q2",7,"Q2",8,"Q3",9,"Q3",10, "Q3",11,"Q4",12,"Q4","None")& "-W"&Text(CEILING( 
( 
DAY( CloseDate ) + 
MOD( DATE( YEAR( CloseDate ), MONTH( CloseDate ), 1 ) - DATE( 1900, 4, 1 ), 7 ) 
) / 7 
))

I need to display the weekly based on the image attached Please suggest me how to modifiy the formula.

Thanks
Sudhir

Hi Guys.

I am trying to have a formula field for the Week Number of the year. So, if opportunity is created on the 3rd January 2016, it would show "Week 1 2016".
I use the report in the Matrix format.
Currently, the field I am using for week number calculation is called "Created Date"
Format of the field is: DD/MM/YYYY (this was changed in the regional settings from the american MM/DD/YYYY format)

I have browsed forums and found many formulas... which none of them work.
One of them, for example:

MOD(FLOOR((Created_Date__c - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1

It gives me the following error:
Error: Invalid custom summary formula definition: Field Created_Date__c does not exist. Check spelling.

Now, I am new in SFDC formulas, so as far as I understand, there is no such field. It should be called Crated Date. But if i use just Created Date - I get error that there is no field Created. If I use formula like this:

MOD(FLOOR(("Created Date" - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1

I get error: Error: Invalid custom summary formula definition: Incorrect parameter type for operator '-'. Expected Number, Date, DateTime, received Text.

I know that I am doing mistake somewhere, but where?
Thank you for the answers!

Hello, 
I am trying to create a field that displays week of the year that the lead was created based off the CreatedDate (Date/Time) Field.

I think I need to first convert the CreatedDate (Date/Time) to a (Date) field and then use a formula to change the date into a Week Number.

The output of the formula should be a number (between 0-52).

This is what I'm working with right now... but this formula has errors:

DAY( DATEVALUE( date/time ))
IF(
2
  CEILING( ( date - DATE( YEAR( date ), 1, 1) + 1) / 7) > 52,
3
  52,
4
  CEILING( ( date - DATE( YEAR( date ), 1, 1) + 1) / 7)
5
)

Any help would be greatly appreciated! 
Hello,

I'm trying to make a call to a WebService that requires the Soap Security Header to be provided in the message. They also require Password Digest.

I am able to POST a message to the service, and getting the response I'm looking for, using a tool such as SOAP UI. In the log I see the Soap Header looks like this

<soapenv:Header><wsse:Security soapenv:mustUnderstand="1" 
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-0A895E4ED2XY1B64BB142239383782811>
    <wsse:Username>irhythmtest</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">kxPMdaV96UNV1OXw0B83IpnwgNc=</wsse:Password>
    <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">LTYzMDgmJTU1MTE5ODgyMjQ2HOZ==</wsse:Nonce>
    <wsu:Created>2015-01-27T09:41:14Z</wsu:Created>
</wsse:UsernameToken></wsse:Security></soapenv:Header>

What I'm trying to do is to create this header in an Apex Class.
I highligheted in BOLD (above) the "variable" fields.

- For Password Digest, I'm generating the string using the process below

            Blob targetBlob = Blob.valueOf('mypass');
            Blob hash = Crypto.generateDigest('SHA1', targetBlob);
            String b64 = EncodingUtil.base64Encode(hash);  

- For Nonce, I'm generating the string using the process below

            Long randomLong = Crypto.getRandomLong();
            String Nounce = EncodingUtil.base64Encode(Blob.valueOf(String.valueOf(randomLong)));

- For Created, I'm generating the string using the process below

            String Create = Datetime.now().formatGmt('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');

I am not sure what goes in the wsu:Id="UsernameToken part of the header. How are tools such as SOAP UI generating a different and accepted Token in each call?

Any help or ideas on this would be highly appreciated

Thanks!
Giorgio

Hello,

 

I am trying to gather the week number of a week within a fiscal year. I have been able to calculate this for the standard 52-week year using the following formula:

 

MOD(FLOOR( ( CloseDate -DATEVALUE("YYYY-MM-DD"))/7),52)+1

 

My issue is that i need to now calculate the fiscal week for a fiscal year that has 53 weeks. 

 

Thanks for the help.

In Sweden and some other parts of Europe the week numbering is often using the ISO 8601 standard that says that the first week of the year is the first week with at least 4 days in the new year. Some consequences of this is that the final dates of one year can be week 52, 53 or even week 1( in the following year). The same goes for the first dates of a year.

 

To be able to do weekly comparison report Year-to-Year with this weeknumbering it is necessary to create custom fields for the opportunity that calculates the Year and Week number for a given close date. Here is one solution using three custom formula fields.

 

Field: Global Sales Report Weekday

Description:  Day 1 = Sunday, 2 = Monday....., 7=Saturday

Formula:  MOD( CloseDate  - DATE(1900, 1, 7), 7)+1

 

Field: Global Sales Report Week Year

Formula: YEAR(CloseDate + (MOD(8- Global_Sales_Report_Weekday__c ,7)-3))

 

Field: Global Sales Report Week

Formula:

FLOOR((CloseDate - DATE( Global_Sales_Report_Week_Year__c ,1,1) +
MOD(
(MOD( DATE(Global_Sales_Report_Week_Year__c,1,1) - DATE(1900, 1, 7), 7)+1)
+1,7)-3) / 7 + 1)

 

Hope this can be of use for anyone else

 

Peter Baeza

InfoAction AB, Sweden

 

  • March 15, 2010
  • Like
  • 3

I am a bit of a beginner at formulas, so hopefully one of you will think this is easy, and be able to help. :-)

 

Customer requirement:

 

Create a formula field that displays the Week Number (as Week 1, Week 2, etc), based on the Date entered on a particular record (same object).

 

Ex: 01/01/09 - 01/04/09 would return a value of "Week 1"  

01/05/09 - 01/11/09 = Week 2

01/12/09 - 01/18/09 = Week 3

 

and so on.....

 

Is using the CASE function the way to go, and if so, what's the shortest way to create this formula?

 

Thank you in advance!

S

 

  • April 20, 2009
  • Like
  • 0
My developer has created a custom class to extend the datasource.connection class and when he hits SAVE, gets the followin error message:

EROR: Compile Error? Type not visible: DataSource.Connection at line 5 column 15.

Line 5 states:
global class  TestUserDataSourceConnection extends DataSource.Connection {

Problem at botton says: Line 5 Type is not visible: DataSource.Connection

Any ideas what may causing the error?