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
Molson94Molson94 

VF: Building URLs with Parameters / Extra Characters being added

Hi all,

Simple question I hope.

I have a custom controller that after creating a new custom object, redirects to the second page in the series.

This is the code i am using for moving to the next page:
public PageReference step2() {
        //when submitted, check the title id against the title records
        tidL = [SELECT id FROM Title__c WHERE Title_ID__c = :tID LIMIT 1];
        if (!tidL.isEmpty()){
            cc.Vendor__c = vendor.get(0).id;
            cc.Title__c = tidL.get(0).id;
            cc.Status__c = 'Open';
            upsert(cc);
            
            PageReference redirect = Page.cc2;
            redirect.getParameters().put('v',vendor.get(0).id);
            redirect.getParameters().put('cc',cc.id);
            redirect.setRedirect(true);
            return redirect;
        }

The end result i am trying to achieve is the next pages url is appended with the following: ?v=VENDORID?cc=CCID
So i can then pull those parameters and do some other validation etc..

What the application is doing however is returning the following:

?cc=a07e0000001qHsNAAU&v=a09e0000002k5ueAAA

The italicized portions are the correct ID fields that i am looking to identify, but the  bolded portions are causing errors when the second page grabs the parameters.

Can anyone help explain why this is the case and/or advise on how to acheive the desired result?

or

If it is simpler, what would be the correct syntax to build out these URLs via string?

Thank you all for your help!
Best Answer chosen by Molson94
Deepak Kumar ShyoranDeepak Kumar Shyoran
There are two type of Id for a record in Salesforce one is 15 digit case sensitive Id i.e, "a07e0000001qHsN" and "a09e0000002k5ue" in your case and another one is 18 digit Id which is case insensitive i.e "a07e0000001qHsNAAU" and "a09e0000002k5ueAAA". The last three digit i.e AAU and AAAId are basically the checksum of starting 15 digit which Salesforce calculates and append to 15 digit id and convert that to case 18 digit case insensitive Id.

I think you are comparing your Id which you get from parameter with a Hard coded value in code which is not a good approach.
You can discard the last three digit easily by using String substring method in Salesforce.

Please mark my answer as a best solution to your question to help others if it solves your problem.

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
There are two type of Id for a record in Salesforce one is 15 digit case sensitive Id i.e, "a07e0000001qHsN" and "a09e0000002k5ue" in your case and another one is 18 digit Id which is case insensitive i.e "a07e0000001qHsNAAU" and "a09e0000002k5ueAAA". The last three digit i.e AAU and AAAId are basically the checksum of starting 15 digit which Salesforce calculates and append to 15 digit id and convert that to case 18 digit case insensitive Id.

I think you are comparing your Id which you get from parameter with a Hard coded value in code which is not a good approach.
You can discard the last three digit easily by using String substring method in Salesforce.

Please mark my answer as a best solution to your question to help others if it solves your problem.
This was selected as the best answer
Molson94Molson94
Hi Deepak,

Thank you for the response and explanation.
i was not aware of the 18 digit ID and how that was rendered.

I think ill be able to find a solution.