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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 8
    Replies
string server = null;
String host = URL.getSalesforceBaseUrl().getHost();
if(host.split('\\.')[2] == 'visual'){
	server = host.split('\\.')[1];            
}
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://' + server + '-api.salesforce.com/services/data/v34.0/sobjects/' + objName + '/describe/layouts/' + recordTypeId);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Sforce-Call-Options', 'client=x');
Http http = new Http();
HTTPResponse res;
res = http.send(req);

This gives response: 

Request
|System.HttpRequest[Endpoint=https://na70-api.salesforce.com/services/data/v34.0/sobjects/Account/describe/layouts/01280000000HmSj, Method=GET]

Response
System.HttpResponse[Status=Service Unavailable, StatusCode=503] 

I also checked  
https://status.salesforce.com/instances/NAX/maintenances and looks all good. 

Can anybody help me figure out why is this occurring for a particular instance only? 
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? 
        
 
global without sharing class addSectionScript implements InstallHandler {
	global void onInstall(InstallContext context) {
		
		try{
	        if(context.isUpgrade() || context.isPush()){
	        	System.debug(LoggingLevel.ERROR,'Instllation is Upgrade or Push. Adding secion to layout.');
	        	
	            //Add Section Through the Metadata API
	            List<String> componentNameList = new List<String>{'Custom_Object_Analysis__c-Custom_Object Analysis Layout'};
		        List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);     
	            Metadata.Layout la =(Metadata.Layout) components.get(0); 

	            // Create Section
	            Metadata.LayoutSection sec = new Metadata.LayoutSection();
	            sec.customLabel = true;
	            sec.detailHeading = true;
	            sec.editHeading = true;
	            sec.label = 'RingLead Data Quality Score';
	            sec.style = metadata.LayoutSectionStyle.OneColumn;

	            // Create Layout Field
	            Metadata.LayoutItem layoutField = new Metadata.LayoutItem();
	            layoutField.page_x = 'Custompage';
	            layoutField.height = 550;
	            layoutField.width = '100%';

	            // Add Layout Field and Column to Section
	            Metadata.LayoutColumn col1 = new Metadata.LayoutColumn();
	            col1.layoutItems.add(layoutField);
	            sec.layoutColumns.add(col1);
	            la.layoutSections.add(sec);

	            // Deploy it to Layout of User.
	            Metadata.DeployContainer dc = new Metadata.DeployContainer();
	            addSectionScriptCallback callback = new addSectionScriptCallback();
	            dc.addMetadata(la);
	            if(!Test.isRunningTest()){
	            	
	            	Id jobid = Metadata.Operations.enqueueDeployment(dc,callback);
	            	System.debug(LoggingLevel.ERROR,'id is:'+jobid);
	            	
	        	}
	        }
    	} catch(Exception e){
    		System.debug(LoggingLevel.ERROR,'Error in Post Script.');
    		sendTestEmail('Error in post install script.' + e.getStackTraceString());
    	}
    }

    public void sendTestEmail(String body){
        
    }
}

I am trying to change the page layout of the custom object when a user upgrades the package using Metadata. 

I am using this code to upgrade the page layout. But when tried to enque the deployment it gives this error. 

Fatal Error
INSUFFICIENT_ACCESS: insufficient access rights on cross-reference id

 
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, 

I have a visualforce page with lightningStylesheets="true" and I am using it in lightning. BUt in lightning, there is no select button for the multiselect picklist (in the image below). Any suggestions for what am I missing? 

User-added image
Hi, 

How should I get a createdDate for the custom field using Apex? 
Hi, 

I have a list with the following format in apex controller. 

Custom__Object_Analysis__c:{Id=a0L1N00000L1izqUAB, Name=All Accounts, CreatedDate=2018-02-15 15:15:12, isCustom__c=false, Fields__c=0, Filter__c=Industry = '', Object_Name__c=account, Tally__c=0}

How do I serialize this? 
JSON.Serialize() gives Uncaught SyntaxError: Unexpected string 
Hi All, 

I have a custom validation error, it is getting displayed on visual force page but my save button keeps running. Below is the screenshot for that. User-added image
<apex:form>

    <apex:pageMessages id ="showmsg"></apex:pageMessages>
    <apex:actionfunction name="lookupDetail" action="{!lookupDetail}" rerender="pnlScriptDupes" />


     <apex:actionfunction name="action_onSave" action="{!onSave1}" oncomplete="testfunc();" rerender="pnlScriptDupes" />
 
 
    <apex:actionfunction name="action_onCancel" action="{!Cancel}" />

    <apex:dynamiccomponent componentvalue="{!Ext.dynamicPageBlock}" rendered="
    
    </apex:pageblock>
    <apex:outputpanel id="pnlScriptDupes">
     
      <div id="pnl-hdn-messages" style="display:none">
      </div>
      
    </apex:outputpanel>
  </apex:form>
 
public PageReference onSave1(){
        Account a = (Account)con.getRecord();

        try{
            insert a;

            String id = ApexPages.CurrentPage().getParameters().get('id');
          
            PageReference ref = new PageReference('/'+a.id);
            ref.setRedirect(true);
            return ref;
        }
        catch(Exception ex){
           
            System.debug(LoggingLevel.ERROR, 'saveError:' + saveError);
            ApexPages.addMessages(ex);
            System.debug(LoggingLevel.ERROR, 'ERROR:  ' + ex);
            System.debug(LoggingLevel.ERROR, 'Inside Catch');
            

        }
       
        return null;
    }



 
Hi All, 

I want to reference a relational field in custom object. For example, Select ID, Contact__r.Name from x_Report__c gives unrecognized property exception in JAVA. 
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
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