Thursday 22 March 2018



In certain circumstances, we need to deactivate trigger temporary or permanently. But, if you open the trigger in Salesforce production environment, you will not see Edit and Delete button.

 In short, deactivate the same trigger in sandbox and deploy it to production. You can deploy with Ant, Force.com IDE, or simple Change Set.

Wednesday 21 March 2018


           Deploy Change Sets from Sandbox to Production

                Step 1) Prepare your Sandbox org

 1. Log in to your sandbox.
 2. Click Setup | select App Setup | Outbound Change Sets.
 3. Click New.
 4. Enter the new Change Set and description, then click Save.
 5. From the "Change Set Components" related list, click Add.
 6. Add profiles to the Change Set for the Users you'd like to grant access.
 7. Select the "Component Type" for the component you want to deploy (for example, Apex class, Apex Trigger).
 8. Select the specific class or trigger name, then click Add to Change Set.
 9. From the "Change Set Detail" related list, click Upload, then select the target Organization as Production
10. Click Upload.
After your upload has completed, you'll receive an email to confirm completion of your Change Set upload.
To complete the migration, an inbound change administrator can deploy the Change Set in the destination production organization.
 Step 2) Complete the deployment in your production org

1. Click Setup | select App Setup | Inbound Change Sets.
2. Under "Change Sets Awaiting Deployment," click your Change Set's name.
3. Click Validate to validate your code. Note: For successful deployment you should have at least 75% code coverage.
4. Click Deploy.




Wednesday 14 March 2018

       System.ListException: Duplicate id in list: 001XXXXXXXXXXXX

Lists can hold duplicate values, but if it contains duplicate sobject IDs and you try to update you'll get the error.

Solution:

1. Create a map of  <id,sobject>
2. Convert the list to Map so that the duplicate IDs are removed.
3. Update the values part of the Map.

Sample code :

// pick up any id from your salesforce org, in this sample it is account id.
id aid = '0017F000002WkkdQAC';

list <account> al = new list <account>();

for(account a : [select id from account where id ='0017F000002WkkdQAC']){
account acc = new account(id = aid);
    al.add(a);
    al.add(acc);
}
//create a map that will hold the values of the list
map<id,account> accmap = new map<id,account>();

//put all the values from the list to map.
accmap.putall(al);
if(accmap.size()>0){
update accmap.values();
}