+ Start a Discussion
André Chay SondaAndré Chay Sonda 
What I need to activate Environment Hub? 
I can't see the option in any place

I have a trial version of Salesforce Professional Edition. 
I need to have other edition to use it? 

Thanks!
 
Best Answer chosen by André Chay Sonda
Raj VakatiRaj Vakati
environment hub is  Available in Enterprise, Performance, and Unlimited Editions


The Environment Hub lets you connect, create, view, and log in to Salesforce orgs from one location. If your company has multiple environments for development, testing, and trials, the Environment Hub lets you streamline your approach to org management.


Configure the Environment Hub so that users at your company can access the app to create and manage member orgs. Then enable My Domain so that you can connect existing orgs to the hub and create SSO user mappings.​​​​​​​


Sign up from here for testing 

https://developer.salesforce.com/promotions/orgs/dx-signup​​​​​​​


Some usefull links 


https://help.salesforce.com/articleView?id=environment_hub_faq_map.htm&type=5
https://help.salesforce.com/articleView?id=environment_hub_best_practice.htm&type=5
https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/environment_hub_faq_where_install.htm​​​​​​​
Robert Davis 1Robert Davis 1 
I have a trigger on the Account that looks into a Custom Metadata Type and if the User Id is there they are allowed to delete the record otherwise they receive an error message.

The trigger acts as expected in testing my problem is I do not understand how to write the test code.

Account Trigger:
trigger AccountTrigger2 on Account ( before delete) 
{
    Account_Trigger_Handler handler = new Account_Trigger_Handler();    
    if(Trigger.IsDelete)
    {
        handler.OnDelete_Account(Trigger.old);
        
    }//End if
}//End class
Trigger Handler:
public with sharing class Account_Trigger_Handler {

    public void OnDelete_Account(List<Account> acct)
    {
        //get user id for current user
        Id uid = UserInfo.getUserId();
        system.debug('User id : '+uid);
        //create a map to put in all the users who are authorized to delete
        Map<Id,Account_Delete_User__mdt> mapAcctDeleteUser = new Map<Id, Account_Delete_User__mdt>(); 
        //loop through the users who are authorized to delete and put them in the map we created just before this
        for(Account_Delete_User__mdt AcctDeleteUser : [SELECT id, UserId__c FROM Account_Delete_User__mdt])
        {
            mapAcctDeleteUser.put(AcctDeleteUser.Userid__c, AcctDeleteUser);
        }//end for
        
        //loop through the records in the trigger and see if the current user is authorized to delete.
        for(Account a: acct)
        {
            if(mapAcctDeleteUser.keyset().contains(uid)== false)
            {
            a.addError('You are not authorized to remove Accounts from Salesforce. Please email Salesforce.admin@XXXXX.net to have record removed.');
            }//end if
        }//end for           
     }//end method
  }
The following is the test class I have so far, but it gets the error: System.AsyncException: Metadata cannot be deployed from within a test

But I do not know how to fix:
@isTest
public class Account_Trigger_HandlerTest {
  
    public static testMethod void OnDelete_AccountTest()
    {
        Profile p2 = [SELECT id FROM Profile WHERE Name ='Standard User'];
        
        User usr2 = new User (LastName ='Boris',
                              FirstName ='Badenov',
                              Email = 'boris.badenov@bullwinkleshow.com',
                              Username = 'boris.badenov@bullwinkleshow.com',
                              Alias = 'boris',
                              Profileid = p2.Id,
                              TimeZoneSidKey ='GMT' ,
                              LanguageLocaleKey = 'en_US',
                              EmailEncodingKey = 'UTF-8',
                              LocaleSidKey = 'en_US');
        insert usr2;
    //---------------------------------------------------------------------
    //https://ashwanisoni.wordpress.com/2017/05/02/create-or-update-custom-metadata-type-via-apex-code-salesforce-summer-17/
        // Set up custom metadata to be created in the subscriber org.
    Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
    customMetadata.fullName = 'Account_Delete_User';
    customMetadata.label = 'User';

    Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
    customField.field = 'UserId__c';
    customField.value = usr2.id;

    customMetadata.values.add(customField);

    Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
    mdContainer.addMetadata(customMetadata);

    // Setup deploy callback, MyDeployCallback implements
    // the Metadata.DeployCallback interface (code for
    // this class not shown in this example)
    CustomMetadataCallback callback = new CustomMetadataCallback();

    // Enqueue custom metadata deployment
    // jobId is the deployment ID
    Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);
    //----------------------------------------------------------------------
        Profile p = [SELECT id FROM Profile WHERE Name ='Standard User'];
        
        User usr1 = new User (LastName ='Fatale',
                              FirstName ='Natasha',
                              Email = 'natasha.fatele@bullwinkleshow.com',
                              Username = 'natasha.fatele@bullwinkleshow.com',
                              Alias = 'natas',
                              Profileid = p.Id,
                              TimeZoneSidKey ='GMT' ,
                              LanguageLocaleKey = 'en_US',
                              EmailEncodingKey = 'UTF-8',
                              LocaleSidKey = 'en_US');
        insert usr1;
        Account acct2 = New Account(Name='Snagglepuss', Type='Prospect', SSN__c = '12385678', CreatedById = usr1.id);
        insert acct2;
        Test.startTest();
            Database.DeleteResult result = Database.delete(acct2,false);
            System.assert(!result.isSuccess());
        Test.stopTest();
        
        
    }
}
The following is the callback function that the test code references:
public class CustomMetadataCallback implements Metadata.DeployCallback {
    public void handleResult(Metadata.DeployResult result,
                             Metadata.DeployCallbackContext context) {
        if (result.status == Metadata.DeployStatus.Succeeded) {
            System.debug('success: '+ result);
        } else {
            // Deployment was not successful
            System.debug('fail: '+ result);
        }                       
    }
//https://ashwanisoni.wordpress.com/2017/05/02/create-or-update-custom-metadata-type-via-apex-code-salesforce-summer-17/  
}
I am just missing the boat on how to fix this.

Really would appreciate any help.

 
Best Answer chosen by Robert Davis 1
Syed Insha Jawaid 2Syed Insha Jawaid 2

Hi Robert

Custom metadata are a part of application configuration like your workflows,validation,object etc. These can be included in changesets,packages etc. 
They aren't specifically your records for which you would need to add @IsTest(SeeAllData=true) which although is not a good practice .Apex tests can see them.You dont have to create records in your test methods.

For better understanding please check out the link mentioned below :
https://developer.salesforce.com/blogs/engineering/2015/05/testing-custom-metadata-types.html

Cheers
Insha

Stanley Ye 18Stanley Ye 18 
Just created a form as below:
I gave the aura:id to the 'Status__c' field 
       
<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">      
            <lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
            <lightning:inputField fieldName="StatusChangeReason__c"/>
            <lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
            <lightning:inputField fieldName="MainReasonForCessation__c"/><br/>                
</lightning:recordEditForm>   

in the js controller: 
I used the below command to retrieve the value of the 'Status__c' field:
component.find('cpe_status_test').get('v.value')

Howeve, in the console log, I see it returned 'undefined'

To investigate further, I tried below:
component.find('cpe_status_test')   -   return  '{addValueHandler: ƒ, addValueProvider: ƒ, destroy: ƒ, getGlobalId: ƒ, getLocalId: ƒ, …}'
component.find('cpe_status_test').getGlobalId()  -  return  '13:0'
component.find('cpe_status_test').getLocalId()  - return 'cpe_status_test' ;


It seems it does return the element but why get('v.value') doesn't work properly?





Thanks



 
Best Answer chosen by Stanley Ye 18
Maharajan CMaharajan C
Hi Stanley,

I think from the record form in the component intialization the fields will not be load in the form.so it's give the Undefined error.

So i will suggest you to use the Force:RecordUpdate in above the record form like below to fetch that record value. And call the doInit once the record is loaded in the force:recordData.


<aura:attribute name="ClientProgRec" type="Object" /> 
<aura:attribute type="Object" name="record"/>

<force:recordData aura:id="recordLoader"
                      recordId="a4p0k000001c8peAAA"
                      fields="Id, Status__c"                       
                      targetRecord="{!v.record}"            
                      targetError="{!v.recordError}"
                      targetFields="{!v.ClientProgRec}"
                      recordUpdated="{!c.doInit}" />

<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">      
            <lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
            <lightning:inputField fieldName="StatusChangeReason__c"/>
            <lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
            <lightning:inputField fieldName="MainReasonForCessation__c"/><br/>                
</lightning:recordEditForm>   


Now in the doInit method you can get the Value for that 

doInit : function(component, event, helper) {
        
        var cpeStatus = component.get("v.ClientProgRec").Status__c;
        console.log('@@@ cpeStatus ==> ' + cpeStatus);
            
    }

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
Pablo LamasPablo Lamas 
Hello,
I currently having and issue with trying to deploy a fix to a trigger class that we have. When I validate it, I receive the following error: 
      Your code coverage is 8%. You need at least 75% coverage to complete this deployment.
The issue is that, this isnt a regular apex class, it is a trigger. From what I understand, triggers need to have >0% code coverage, which I have 8% code coverage. Any ideas as to why this is being evaluated at the 75% code coverage and not at the >0% code coverage. 
Best Answer chosen by Pablo Lamas
Kenneth Bowman 16Kenneth Bowman 16
Hi Pablo,

Even though an individual, particular trigger doesn't need more than 1% coverage, you still must have 75% complete code coverage for the entirety of the Org in order to deploy any apex. 

Best practice is to treat your trigger as though it is an Apex class and keep its code coverage above 75% individually, and strive for 100% coverage. 

Hope that helps!

 
EranVEranV 
It seems like Apex code of Lightning Component server controllers aren't getting captured in the standard debug logs. Can anyone confirm and/or suggest a way to debug those controllers?

Thanks!
Best Answer chosen by EranV
Raj VakatiRaj Vakati
It will capture in same logs  ..  Set the Debug Log levels to FINEST 

https://help.salesforce.com/articleView?id=code_add_users_debug_log.htm&type=5
Add some system.debug log and you can able to see 

https://help.salesforce.com/articleView?id=code_add_users_debug_log.htm&type=5
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log.htm
TibUbqTibUbq 
I've come across a trigger in our system but i'm not sure what it's doing? Could anyone take a look and see if they can break down what exactly it's doing?

trigger Trigger_Name on Account (after insert) {

    Class_Name CN1 = new Class_Name();
    CN1.Account_Link(Trigger.new);       
}   
 
public with sharing class Class_Name {
public void Account_Link(list<account> acs){
    list<account> marked_acs = new list<account>();
    for(Account ac : acs){
        if(ac.industry == 'Link'){
             marked_acs.add(ac);
        }
     }     
    list<Account_Link__c> Link_acs = new list<Account_Link__c>();
    for(Account ac : marked_acs){
Linked_Account__c con_ac = new Linked_Account__c(name = ac.name, account__c = ac.id);
Linked_acs.add(con_ac);
        }
        insert Linked_acs;       
    }   
}
 
Best Answer chosen by TibUbq
Maharajan CMaharajan C
Hi ,

The Main purpose of this trigger is creating the Linked Account Custom Object Record when the new Account is Link Industry.

trigger Trigger_Name on Account (after insert) {
    Class_Name CN1 = new Class_Name();    // Intializing  the Helper Class
    CN1.Account_Link(Trigger.new);       // passing the newly inserted accounts to the helper. 
}    
 
public with sharing class Class_Name {
public void Account_Link(list<account> acs){
    list<account> marked_acs = new list<account>();
    for(Account ac : acs){
        if(ac.industry == 'Link'){        //if the incoming account industry is Link then that Account data is added to marked_acs list to proceed further
             marked_acs.add(ac);
        }
     }      
    list<Account_Link__c> Link_acs = new list<Account_Link__c>();   
    for(Account ac : marked_acs){        // Iterating the above list which holds the industrt Accounts.
Linked_Account__c con_ac = new Linked_Account__c(name = ac.name, account__c = ac.id);    //  Creating the Child Record data for industry                                                                                                                                               //account to insert in the Linked Account Custom object
Linked_acs.add(con_ac);
        }
        insert Linked_acs;        // insert the Linked Account records in Linked Account Custom object
    }    
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
VSK98VSK98 
Hi All,

I am getting the error when I run the test class.
System.JSONException: Unexpected character ('C' (code 67)): was expecting comma to separate OBJECT entries

I have created the mock class, in that I am sending the body as below.
 
res.setBody('{"value": [{'+
        '"groupid": 1,'+
       '"group_name": "Test",'+
        '"sub_customer": "[{\"CustomerId\":\"9488491\",\"CustomerName\":\"Test\",\"Street\":\"Test\",\"City\":\"PENRITH\",\"PostalCode\":\"275\",\"Country\":\"Test\",\"Assetcnt\":\"6\"}]"}]}');

I am getting the error in Apex class
SearchResult obj=(SearchResult)JSON.deserialize(resp.getBody(), SearchResult.class);

Wrapper class :
 
Public class value{
        
        @AuraEnabled
        public Integer groupid {get; set;}
        @AuraEnabled
        public string group_name {get; set;}
        @AuraEnabled
        public String sub_customer {get; set;}
        
        
    }
    
    public class SearchResult {
        @AuraEnabled
        public List<value> value;
        
        public SearchResult(List<value> liList) {
            value = liList.clone();
        }
    } 
    
    Public class Value_out{
        @AuraEnabled
        public string group_name;
        @AuraEnabled
        public string groupid;
        //srini-added for parent level sum of assets
         @AuraEnabled
        public String sumofAssets;
        @AuraEnabled
        public list<sub_customer> children;
    }
    public class sub_customer{
        @AuraEnabled
        public string CustomerName;
        @AuraEnabled
        public string CustomerId;
        @AuraEnabled
        public string Street;
        @AuraEnabled
        public string City;
        @AuraEnabled
        public string PostalCode;
        @AuraEnabled
        public string Country;
        @AuraEnabled
        public string Assetcnt;
    }

Regards,
VSK98​​​​​​​
 
Best Answer chosen by VSK98
AmanSharma06AmanSharma06
Well json exception occurred due to incorrect json string. Tried with below json and it worked for me:

 String jsonStr ='{"value": [{'+
        '"groupid": 1,'+
       '"group_name": "Test",'+
        '"sub_customer": "[{\\"CustomerId\\":\\"9488491\\",\\"CustomerName\\":\\"Test\\",\\"Street\\":\\"Test\\",\\"City\\":\\"PENRITH\\",\\"PostalCode\\":\\"275\\",\\"Country\\":\\"Test\\",\\"Assetcnt\\":\\"6\\"}]"}]}';
SearchResult v = (SearchResult)JSON.deserialize(jsonStr, SearchResult.class);

Output :
SearchResult:[value=(value:[group_name=Test, groupid=1, sub_customer=[{"CustomerId":"9488491","CustomerName":"Test","Street":"Test","City":"PENRITH","PostalCode":"275","Country":"Test","Assetcnt":"6"}]])]
 
Darshit Pathak 3Darshit Pathak 3 
If I append lastModified date everytime the record is updated it will exceed the name field character limit that is 80.
And also to get the latest LastMpdifiedDate I need to update the record in afterUpdate by doing DML. so it may go in infinite recursive trigger call.

I am not getting how to acomplish this?
Best Answer chosen by Darshit Pathak 3
Raj VakatiRaj Vakati
This code is not bukfiled but wokring  .. bulkfy the code
public class checkRecursive {
    public static Set<Id> SetOfIDs = new Set<Id>();
}



try this code
 
trigger AccountUpdate on Account (after update) {
    List<Account> accUp = new List<Account>() ;
    for(Account a :Trigger.new){
        If(!checkRecursive.SetOfIDs.contains(a.Id)){
            List<String> parts = a.Name.split('--');
            if(parts.size()>1){
              //  a.Name = parts[0]+ '--'+String.valueOf(a.LastModifiedDate);           
            }
            checkRecursive.SetOfIDs.add(a.Id);
            Account  a1 =[Select Id , Name from Account where Id =:a.Id] ; 
            a1.Name = parts[0]+ '--'+String.valueOf(a.LastModifiedDate);
            update a1 ;
            // accUp.add(a);
            //   update accUp;
            
        }
        
    }
    
}

 
Sandilya kumarSandilya kumar 
Create a custom object, Work Order object. It should have a country field. When we are creating a new record for WorkOrder, The WorkOrder's owner should assign to a user who is specific to the Region based on the country field. 

Create two custom objects( Region__c ,  Region_Country__c). Region object should have User lookup. Region_Country__c should have all the countries list with Regions.
trigger WorkOrders on WorkOrder (after insert) {
    set<Country__c> con =new set<Country__c>();
    list<Workorder__C>worklist=new list<Workorder__C>();
    list<Workorder__C>work_list=new list<Workorder__C>();
    
    list<Region__c>Reglist=new list<Region__c>();
   
    if(trigger.isinsert)                              
    {
        for(Region__c R:trigger.new)
        {
            Reglist = [select User__c from Workorder__C ];
        }
    }
    if (trigger.isdelete)                         
    {
        for(contact con:trigger.old)
        {
            accid.add(con.accountid);
        }
    }
    acclist=[SELECT id,name FROM account WHERE id in:accid];
    contactlist=[SELECT id,name,accountid FROM contact WHERE accountid in:accid];
 

}

Since am new to developing am trying to solve the use case,please can anyone help me .
thanks in advance.
Best Answer chosen by Sandilya kumar
Raj VakatiRaj Vakati
try this code
 
trigger WorkOrders on WorkOrder (before insert) {
	
	Set<String> str = new Set<String>() ; 
	
	for(WorkOrder w : trigger.new){
		str.add(w.country__c) ;
	}
	
	List<Region_Country__c> regCoun = [Select Name , Id ,User__c  from Region_Country__c where Name IN  : str]; 
	
	Map<String , Region_Country__c> mapOf = new Map<String , Region_Country__c>() ; 
	
	
	for(Region_Country__c r : regCoun){
		mapOf.put(r.Name , r) ; 
	}
	
	
	for(WorkOrder w : trigger.new){
	Region_Country__c c = mapOf.get(w.country__c) ; 
	w.OwnerId =c.User__c;
	}
	
   

}

 
Best Answer chosen by Aladdin US
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Workflows are available in Enterprise, Performance, Unlimited, and Developer Editions.

Workflows for Professional Edtion are available as a paid add-on though (needs to be requested with Support). And it is available as an add-on from the AppExchange: Have a look at the Workflow for Professional Edition App on the AppExchange.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas