• Dippan Patel
  • NEWBIE
  • 140 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 33
    Questions
  • 20
    Replies
Hi All, 

How do I save the dependent picklist with no value even though it is required using Apex. 

Below is my visualforce page and controller code:
<apex:pageBlockSection title="Content Section" columns="1">

      <apex:pageBlockButtons >
	    <apex:commandButton action="{!SaveRecord}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
     </apex:pageBlockButtons>

     <apex:inputField id="Street__c" label="Street " value="{!Street__c}"/>
     <apex:inputField id="City__c" label="City " value="{!City__c}"/>
      <apex:inputField id="State__c" label="State " value="{!State__c}"/> // dependent field
      <apex:inputField id="Country__c" label="Country " value="{!Country__c}"/> //controlling field
      
 </apex:pageBlockSection>


//Controller 
public class Test{

public Test(ApexPages.StandardController sc)
    {
        obj = (TestAccount__c) sc.getRecord();
}

public ApexPages.PageReference SaveRecord()
{
        try{
            insert obj;
            PageReference pr = new PageReference('/' + Obj.id);
            return pr;
        }
        catch (Exception e){
            System.debug(LoggingLevel.ERROR, e.getMessage());
            ApexPages.addMessages(e);
            return null;
        }
}
}

oth Country__c and State__c fields are required fields in field definition. The above code gives error "Required fields missing : [State]"  incase of countries with no states values. 
Hi All, 

I am having a simple visualforce page code creates a record of an object. The state and country fields are picklist and state is dependent on Country. Below inputfield tag shows proper dependency when fields are displayed but errors on save if state is null. 
 
<apex:pageBlockSection title="Content Section" columns="1">

      <apex:pageBlockButtons >
	    <apex:commandButton action="{!SaveRecord}" value="Save"/>
            <apex:commandButton action="{!cancel}" value="Cancel"/>
     </apex:pageBlockButtons>

     <apex:inputField id="Street__c" label="Street " value="{!Street__c}"/>
     <apex:inputField id="City__c" label="City " value="{!City__c}"/>
      <apex:inputField id="State__c" label="State " value="{!State__c}"/>
      <apex:inputField id="Country__c" label="Country " value="{!Country__c}"/>
      
 </apex:pageBlockSection>

Controller code: 
 
public ApexPages.PageReference SaveRecord()
{
        try{
            insert obj;
            PageReference pr = new PageReference('/' + Obj.id);
            return pr;
        }
        catch (Exception e){
            System.debug(LoggingLevel.ERROR, e.getMessage());
            ApexPages.addMessages(e);
            return null;
        }
}


If Country has no state value, the above code gives error Required fields are missing: [State] on Save. 

 
Hi All, 

I am using Source Code Scanner for scanning my code. But it isn't identifying all the issues that come with Salesforce's security report. 

How do I identify all the issues before submitting my app again? 

Thank you. 
Hi All, 

I have a custom visualforce page and custom controller for entering a record. 

When I click on Save and New button, it works fine the first time but I again fill out the record details and click on the Save and New button, it goes in infinte loop and doesn't redirect to new record page. The record gets saved though. Just not redirected. 

P.S. Classic works fine, The visualforce page uses lightning style sheets in Lightning mode. The issue is in Lightning. 

Below is my code 
<apex:form >

<apex:actionfunction name="action_onSaveAndNew" action="{!onSaveAndNew}"  />

</apex:form>


Controller: 

public virtual PageReference onSaveAndNew2(){

				//save record
				String s = '/' + ('' + object.subString(0, 3) + '/e?';
				System.debug(loggingLevel.error, 'String s:    ' + s);
				ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
				PageReference page = new PageReference(s);
				page.setRedirect(true);
				return page;
			
		}

Any idea why it is not redirecting the second time? 

Thank you.  
Hi, 

I want to run a SourceCode scan for my latest version of the package. But whenever I login to scanner and select the org id and package id, I cannot find the latest version in the dropdown. 

My latest version should be something like 1.375 and in the dropdown I have 1.325, 1.324, 1.323. 

What can be reason for this? 

Thank you,
Dippan 
Hi All, 

Can anybody provide me a link to a managed package that might have deprecated fields on either of Leads or Contacts or Accounts? 

I've installed several free apps from Appexchange but no luck yet. 

If you know any, can you please let me know? 

Thank you,
Dippan 
Hi All, 

Is there a way to get all the deprecated fields of managed package from Lead? 

I have many fields on page layouts of Leads which are deprecated by the managed package. I want to get a list of all such fields using apex. 
//Visualforce page for pageBlockTable

<apex:page standardController="Loan__c" extensions="AmoSchedRelatedListExtension">
    <apex:pageBlock title="">
        <apex:pageBlockTable value="{!Loan__c.amortization_line_items__r}" var="ali">
            <apex:column value="{!ali.Period__c}"/>
            <apex:column value="{!ali.Month__c}"/>
            <apex:column value="{!ali.Principal_Balance__c}"/>
            <apex:column value="{!ali.Monthly_Payment1__c}"/>
            <apex:column value="{!ali.Interest__c}"/>
            <apex:column value="{!ali.Principal_Payment__c}"/>
            <apex:column value="{!ali.Consulting_Fee__c}"/>
            <apex:column value="{!ali.Adjusted_Principal__c}"/>
            <apex:column value="{!ali.Adjusted_Consulting_Fee__c}"/>
            <apex:column value="{!ali.Total_Payment__c}"/>
            <apex:column value="{!ali.Remaining_Principal_Balance__c}"/>
            <apex:column value="{!ali.Interest_Payments_Received__c}"/>
            <apex:column value="{!ali.Consulting_Fee_Payments_Received__c}"/>
            <apex:column value="{!ali.Principal_Payments_Received__c}"/>
            <apex:column value="{!ali.Total_Payments_Received__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
 
//Apex Class attempting to order the block table in ascending order by Period

public with sharing class AmoSchedRelatedListExtension
{
    private final Id loanId;
    public List<Amortization_Line_Item__c> alis { get; set; }
 
    public AmoSchedRelatedListExtension(ApexPages.StandardController stdController)
    {
        loanId = stdController.getId();
        alis = [select Id
                              ,Period__c
                              ,Month__c
                              ,Principal_Balance__c
                              ,Monthly_Payment1__c
                              ,Interest__c
                              ,Principal_Payment__c
                              ,Consulting_Fee__c
                              ,Adjusted_Principal__c
                              ,Adjusted_Consulting_Fee__c
                              ,Total_Payment__c
                              ,Remaining_Principal_Balance__c
                              ,Interest_Payments_Received__c
                              ,Principal_Payments_Received__C
                              ,Consulting_Fee_Payments_Received__c
                              ,Total_Payments_Received__c
                     from Amortization_Line_Item__c
                   where Loan__c =:loanId
               order by Period__c ASC];
    }
}
Hi everyone,

I'm attempting to add a visualforce page to a lightning record page that displays the related Amortization Line Items of a Loan. Both Loan and Amortization Line Item are custom objects. My intent is to use apex:pageBlockTable to display the related list with more than the standard 10 columns (if there is a better way to achieve this, please  recommend).

As you can see my code above, I have the visualforce page and an apex class which I was hoping would correctly order by period ascending (starting at 1 or 0, depending on the loan). 

On one record, it almost worked but it started at period 4, listed the remaing rows correctly until the final period 36 and then just had no order to it for periods 2, 3, and 1. Other records just order by Period descending.

Any help is much appreciated. Thank you!
User-added image
User-added image
Hi All, 

I have a managed package connected to my production org - where licensing is setup. 
​​​​
I have a user who has installed the package which created a License in my org. Even though I upgrade the license, user still sees it as expired. Below is the screenshot of the license in users org and expiration date in my prod org. 

Any idea why it is not upgrading in user's org? 
User-added imageUser-added image
Hi All, 

I have hardcoded client id and client secret in my code. Salesforce review mentioned to use protected custom settings to store sensitive information. 

So, I created a protected custom setting with two fields client id and client secret. I saved the values in it at  Default Organization Level Value. This custom setting is added to my managed package.

I am able to access it in the developer org, but if my package is installed in another org, it returns null. Below is the code used to access the client id
Access_Key__c authTokenSetting = Access_Key__c.getOrgDefaults();
String rawcryptoKey = authTokenSetting.UniqueEntry__Crypto_Key__c;
System.debug(LoggingLevel.DEBUG, 'Raw crypto key:    ' + rawcryptoKey);

 
Hi All, 

I want Salesforce instance name to add a remote site.
Below is my code: 
String host = URL.getSalesforceBaseUrl().getHost();
String server = host.split('\\.')[1];
String direct =  'https://' + server + '-api.salesforce.com';

I get proper server names such as CS10, CS94 in case of Developer orgs and production. 

However, in case of some sandboxes, I get server as visualforce.
 
Due to this the variable direct turns out to be https://visualforce-api.salesforce.com instead of https://yourdomain-api.salesforce.com

Not able to understand why? 
        
 
Hi All, 

I have a managed packaged installed in production. It works well in prod but not in full copy sandbox. What can be the issue? 

Thanks,
Dippan 
Hi Everyone, 

I want to override custom object new button with my visualforce page. After selecting the page to override on the custom object new button, I am getting the below error.  Error overriding visualforce page
​I have been hitting this error with our Trigger implementation and I could use some help in figuring out how to deal with it.

We have a managed package that we expose through the AppExchange
  • Someone installs, we get a lead created by the License Management Application within our org.
  • I have Lead Trigger that runs  "After Create"
  • The trigger is queueing an @future task to callout to “our service”
However, the LMA seems to be running in the context of a user from a different organization, and the @future call that I have is also running in this same user context.
The result is an exception:
Apex script unhandled exception by user/organization: 005x0000000xxxx/00Dx0000000xxxx
Failed to invoke future method 'public static void Report(String, String)' on class 'TriggerCallback' for job id '707i00000xxxxxx'
caused by: System.CalloutException: Callout loop not allowed
Class.TriggerCallback.Report: line 109, column 1

From my reaing online,it seems the callout is failing because it is running as the user in the LMA, which is not a user in out organization.  

Can I ignore this? Are the other scenarios that my trigger will run in the context of an external user?
Can I detect this and suppress this without trapping ALL CalloutExceptions?

Any suggestions would be much appreciated