• Anil Kamisetty
  • NEWBIE
  • 216 Points
  • Member since 2014

  • Chatter
    Feed
  • 5
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 68
    Replies
I am new to this. please help me to write a test class of below trigger which should have 75% coverage please:

trigger AccountOperations on Account (after update) {    
      if (trigger.isUpdate){     
    Set<Id> setAccountNameChangedIds = new Set<id>();
        for (Account oAccount : trigger.new){
            Account oOldAccount = trigger.oldMap.get(oAccount.Id);        
            boolean bIsChanged = (oAccount.name != oOldAccount.Name);
             if(bIschanged){
                      Util.callWebService(oAccount.AccountNumber, oAccount.Name);          
     }     
            
      }
      }
}

}
I am looking to create a trigger off of a custom object (ObjA - Looks up to Accounts and Opportunities) that will create a record in custom object (ObjB) based on fields from ObjA and some related fields from Accounts/Opportunities.
I receive errors that my related fields do not exist. Can anyone provide insight?
 
trigger OpptyHierarchy on Additional_Account__c (after insert) {
	List<Opportunity_Hierarchy__c> recordsToInsert = new List<Opportunity_Hierarchy__c>();
	for (Additional_Account__c l : Trigger.new) {
		if (l.IsInsert) {
			Opportunity_Hierarchy__c la = new Opportunity_Hierarchy__c();
			V.Account__r.Name = O.Account_Name__c;
			v.Name = o.Account__c;
			v.Account__r.Enterprise_Account__r.Name = o.Enterprise_Account__c;
			v.Account__r.Billing_Location__r.Name = o.Main_Account__c;
			v.Opportunity__c = o.Opportunity__c;

	
			recordsToInsert.add(la);
		}
	}
	insert recordsToInsert;
}

 
Hi

I have created a custom object "Migrations". It has a look up relationship to the Account Object because I need to be able to pull history on a field called "Migration Stage". Now I've been asked to pull in some fields from the Account Object, but I can't do this because it's not setup with a Master Detail Relationship to the Account Object. How can create a formula field or get information from the Account Object?

Thank you
Nancy
Hi and thanks for your replies.

Requirements were to do a duplicate check on Account Name and Zipcode.   I created a custom field and did the workflow update and validation rule and everything worked great...BUT the error message is ugly.

Is there a way to provide a clean error message?

I ended up writing a trigger, which gives me full control over the error message, but would like to learn a different approach.

Regards.
I am trying to create a field that sets a date to the 1st of the next month after an opportunity is marked close won.  I am not sure how to create that formula.  
Fields on an Object can be obtained by the following statement.
Note : Asset is the Object API
Map<String,Schema.SObjectField> mfields = Schema.getGlobalDescribe().get('Asset').getDescribe().fields.getMap();
System.debug('Map size = ' + mfields.size()) ; << 26 not 31

I am wondering why the number of elements is returned as 26 not 31 ? Following elements are missed out. List of fields not reported are  productcode, assetprovidedbyid, assetservicedbyid, isinternal, assetlevel (total 5 fields).

Why not all fields are reported in the SCHEMA Class ? As it is salesforce class, it should report everything. On top of it, ASset is a standard object and we are talking about standard fields only

On the Asset object, the standard field API Names are given below (total : 31)

id,contactid,accountid,parentid,rootassetid,product2id,productcode,iscompetitorproduct,createddate,createdbyid,lastmodifieddate,lastmodifiedbyid,systemmodstamp,isdeleted,name,serialnumber,installdate,purchasedate,usageenddate,status,price,quantity,description,ownerid,assetprovidedbyid,assetservicedbyid,isinternal,assetlevel,stockkeepingunit,lastvieweddate,lastreferenceddate
Attachments are being replaced by FILES and everyone is encouraged to use FILES going forward. Files can be added to any record and at the same times, User can post files to Chatter. Also there is a concept of Private Files (Accessible by the Owner or Creator).

What is the best method to check if the User has access to Create / Update / Delete a File in Apex ?

Colloboration might help for files in a folder but not for Personal Files. What is the best method to address this in Apex ?
My requirement is to schedule a Job every 30 minutes. I can do this using two CRON Expresssions (as given below), but I want to see if we can do this in one expression ? Advantage of having one single job is that "if the job take more than 30 minutes to process, second job wont fire". By having two different expressions, they can be running together.

String cronStr1 = '0 00 * * * ?';
String cronStr2 = '0 30 * * * ?';
Salesforce allows to record Remote Site, which can be used while using the HTTP Requests. Need some insight in the following items ?

Can the Remote Site be querried in Apex ?
Can the Remote Site setting be created in Apex ?

If true, do we have any examples for that.

Any help is greatly appreciated.
Apex Triggers and Classes take time in processing the data. Salesforce has set Governer limits saying that max of 10 Seconds for an UI operation and 60 seconds for a batch operation.

Is there any where in APEX programming where in the Developer can check the amount of processing time (CPU) utilized so far ? Based on the time, take appropriate action.
Apex support Schema Call to get properties on the Salesforce objects. How can I tell if an Object Supports a Trigger or not ? Similarly, how can I say if it can have a Field Set created ? Is there any method which tell me this information.

If not using Schema, if there is another way to get this information, please share that too.

Note : If I know the Object name, I can use SCHEMA calls to get the Object and field set information (if it exists, not that it can support). Here the need is to know which objects supports Field Set / Trigger creation. If you can notice the SCHEMA.SObjectType results, many new objects will be noticed not just Salesforce objects (probably they are required for system).
View is one of the Standard buttons in Salesforce. This button was overwritten for the Account Page with a Visual force page. As such, visual force page is seen on the IPAD version (Salesforce1).

When a Account record is viewed using a Standard layout on IPAD in Saleforce1, the publisher menu is shown (i.e. Plus Sign is shown on the bottom right corner of the Record detail page) by default. This menu is missing when used a Visual force page (View button on the Account Object). How can I show the Publish Menu (Plus Sign) on a Visual Force page in Saleforce1 ? Is that posisble ?
View is one of the Standard buttons in Salesforce. This button was overwritten for the Account Page with a Visual force page. As such, visual force page is seen on the IPAD version (Salesforce1).

When a Account record is viewed using a Standard layout on IPAD in Saleforce1, the publisher menu is shown (i.e. Plus Sign is shown on the bottom right corner of the Record detail page) by default. This menu is missing when used a Visual force page (View button on the Account Object). How can I show the Publish Menu (Plus Sign) on a Visual Force page in Saleforce1 ? Is that posisble ?
I am new to this. please help me to write a test class of below trigger which should have 75% coverage please:

trigger AccountOperations on Account (after update) {    
      if (trigger.isUpdate){     
    Set<Id> setAccountNameChangedIds = new Set<id>();
        for (Account oAccount : trigger.new){
            Account oOldAccount = trigger.oldMap.get(oAccount.Id);        
            boolean bIsChanged = (oAccount.name != oOldAccount.Name);
             if(bIschanged){
                      Util.callWebService(oAccount.AccountNumber, oAccount.Name);          
     }     
            
      }
      }
}

}
Attachments are being replaced by FILES and everyone is encouraged to use FILES going forward. Files can be added to any record and at the same times, User can post files to Chatter. Also there is a concept of Private Files (Accessible by the Owner or Creator).

What is the best method to check if the User has access to Create / Update / Delete a File in Apex ?

Colloboration might help for files in a folder but not for Personal Files. What is the best method to address this in Apex ?
My requirement is to schedule a Job every 30 minutes. I can do this using two CRON Expresssions (as given below), but I want to see if we can do this in one expression ? Advantage of having one single job is that "if the job take more than 30 minutes to process, second job wont fire". By having two different expressions, they can be running together.

String cronStr1 = '0 00 * * * ?';
String cronStr2 = '0 30 * * * ?';
Hi ,

I have written a test class nad  I am getting this error in test class (System.QueryException: List has no rows for assignment to SObject), please help me . below is my test class and apex class 
 
public without sharing class CountCon {
    Integer count = 0;
    public Account a {get;set;}        
    
    public CountCon()
    {
        Account a = new Account();
        a = [Select NumberOfEmployees from Account where id = '0019000000DNnwo'];
        if(a.NumberOfEmployees != null)
            count = a.NumberOfEmployees;
    }           
    public PageReference incrementCounter() {
            count++;
            try
            {
                a = [Select id from Account where id = '0019000000DNnwo'];
                a.NumberOfEmployees = count;
                update a;
            }
            catch(exception e)
            {
                ApexPages.addMessages(e);
            }
            return null;
    }
       
                       
    public Integer getCount() {
        return count;
    }
}


Test class



@istest
public class CountCon_test
{ 
 static testmethod void test()
 {
 Account acc= new Account();
 Acc.name='test';
 insert Acc;
 
 CountCon cn = new CountCon ();
 cn.incrementCounter();
 cn.getCount();
 
 }
}

User-added image
Thanks,
Chanti.
I am looking to create a trigger off of a custom object (ObjA - Looks up to Accounts and Opportunities) that will create a record in custom object (ObjB) based on fields from ObjA and some related fields from Accounts/Opportunities.
I receive errors that my related fields do not exist. Can anyone provide insight?
 
trigger OpptyHierarchy on Additional_Account__c (after insert) {
	List<Opportunity_Hierarchy__c> recordsToInsert = new List<Opportunity_Hierarchy__c>();
	for (Additional_Account__c l : Trigger.new) {
		if (l.IsInsert) {
			Opportunity_Hierarchy__c la = new Opportunity_Hierarchy__c();
			V.Account__r.Name = O.Account_Name__c;
			v.Name = o.Account__c;
			v.Account__r.Enterprise_Account__r.Name = o.Enterprise_Account__c;
			v.Account__r.Billing_Location__r.Name = o.Main_Account__c;
			v.Opportunity__c = o.Opportunity__c;

	
			recordsToInsert.add(la);
		}
	}
	insert recordsToInsert;
}

 
I want to track a long field on chatter.But i came to know the standard functionality of salesforce that rich / long field's old and new value are not posted.

I hope this can be achieved using apex .

Could you please guide me how can i achieve this.

Thanks in advance and a very happy weekend Samir

A customer received this exception:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Apex script unhandled exception by user/organization: <userId>/<orgId>

Visualforce Page: /apex/g2wintegration__g2wInitialize

 

caused by: System.ListException: Row with duplicate Name at index: 2

Class.g2wIntegration.g2wUtils.g2wAccessTokenURL: line 99, column 1
Class.g2wIntegration.g2wInitializeController.autoRun: line 24, column 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Line 99 refers to this line, which invokes the code to grab the custom list setting rows:

Map<String, G2WAccessTokens__c> tokens = G2WAccessTokens__c.getAll();

 

I interpret that error as there are two custom setting rows with the same name - is that accurate? If so, there seems to be a bug in Custom Settings.

In any custom list setting, the name must be unique, but somehow this was not the case for this customer.

 

We set the name to the UserId and have additional checks to ensure if the setting exists, that it gets updated versus trying to insert a new one. Even if code wasn't in place, inserting a 2nd row with the same name throws an exception in Apex, but that didn't happen.

 

Is there any way 2 custom list setting rows can be inserted twice?  All of our tests to reproduce this issue throw exceptions as Apex doesn't allow inserting 2 with the same name.  

Hi All 

 

I have a requirement of tracking all the field changes on every Object of my Salesforce Organisation. 

Is there any APP on APP exchange that supports the above functionality . 

 

Thanks In Advance

Adil

 I need to fetch history of user record in Apex Class. Is there any way to enable history tracking on User Obejct. I do not see "Set History Tracking" button above User Fields like we see in Account object.

Hello,

 

I have two custom fields under Account. I want to setup history tracking for this two field but this Account already exceed the field limits for setup tracking. There are already 25 field under Account, whom had setup the the history tracking. 

 

So can I implement this history tracking by writing Trigger on Account ? If Yes then how can i do? 

I am new to Trigger..so please explain me briefly.

 

 

Thanks,

Hit

  • February 01, 2011
  • Like
  • 0