• AcMEGX
  • NEWBIE
  • 30 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 20
    Replies
The API seems to be lacking. The field IsPersonAccount is part of the Account but I get an error when I try to select it in my query against "Account".

Hi Experts,

 

I am trying to parse an XML with CDATA embeded.  I was wondering if there is a Dom.Document class function equivalent for XmlStreamReader "setCoalescing(boolean)" function to parse the XML

 

Thanks in advance

 

Regards,

G

  • April 28, 2010
  • Like
  • 0
Hi All,

I am looking for a PHP outbound messaging listener sample code. If someone can point me in the right direction. I would appreciate it very much.
  • August 22, 2008
  • Like
  • 0
Hi All,

    I would like to call an APEX web service from an SQL Trigger. How would I go about doing that?  If someone can post generic code or point me to the right way, that would be great. Thanks in advance.

AcMEGX
  • August 06, 2008
  • Like
  • 0
Hi All,

    Good day. Is there a way to set the record type of a record to be saved via VF? Thanks!

Hi,

 

I am getting 'Too many script statements: 50001' exception in my trigger when I do a mass insert. I have not put any DML statements inside any for loop but still I am getting the error.

 

I have a object named Goal and the trigger is on insert. I need to insert all junction object records associated with the Goal object whenever any Goal record is inserted. There are 3 junction objects associated with the Goal - Insurance/Asset/PortfolioReport.

 

Here is the piece of code

 

trigger CreateGoalAssociations on Goal__c (after insert) {
	List<GoalAssetAssociation__c> assetList = new List<GoalAssetAssociation__c>();
	List<GoalInsuranceAssociation__c> insuranceList = new List<GoalInsuranceAssociation__c>();
	List<GoalIAULIPAssociation__c> pReport = new List<GoalIAULIPAssociation__c>();
	Map<Id, Id> entityIds = new Map<Id, Id>();
	Double d= 0;
	Map<Id, Id> goalAccountMap = new Map<Id, Id>();
	List<Goal__c> goalList = new List<Goal__c>();
	
	for(Goal__c g:Trigger.new){
		goalAccountMap.put(g.Id, g.Entity__c);
		goalList.add(g);
	}
    for(Account a: [select Id,Parent_Entity__c from Account where Parent_Entity__c IN :goalAccountMap.values()]){
		entityIds.put(a.Id, a.Id);
	}
    for(Asset__c a: [select Id, Asset_Type__c from Asset__c where Entity__c IN :goalAccountMap.values()
    					OR Entity__c IN :entityIds.keySet()]){
    	
    	for(Goal__c g: goalList){
    		GoalAssetAssociation__c gA = new GoalAssetAssociation__c(Goal__c = g.Id, Asset__c = a.Id, Allocation__c = d);
    		assetList.add(gA);
    	}
    }
    
    for(Insurance__c i: [select Id, Policy_Number_or_Name__c from Insurance__c where Entity__c IN :goalAccountMap.values()
    						OR Entity__c IN :entityIds.keySet()]){
    	for(Goal__c g:goalList){
    		GoalInsuranceAssociation__c gI = new GoalInsuranceAssociation__c(Goal__c = g.Id, Insurance__c = i.Id, Allocation__c = d);
    		insuranceList.add(gI);
    	}
    	
    }
    
    for(Portfolio_Report__c p: [select Id, Portfolio_Type__c  from Portfolio_Report__c where Entity__c IN :goalAccountMap.values()
    							OR Entity__c IN :entityIds.keySet()]){
    	for(Goal__c g:goalList){
    		GoalIAULIPAssociation__c gP = new GoalIAULIPAssociation__c(Goal__c = g.Id, Portfolio_Report__c = p.Id, Allocation__c = d);
    		pReport.add(gP);
    	}
    }
     insert assetList;
     insert insuranceList;
     insert pReport;
     
}

 

Is there any way I can modify the code to avoid the errors. I have highligted the places where I am getting the error.

 

Any help on this will be very much appreciated.

 

Many Thanks,

Jina

I read the apex developer's guide and at  the bulk trigger part found this "

The code block of a trigger cannot contain the static keyword.Triggers can only contain keywords applicable to an inner
class."

what does this mean?

 

Has anybody succesfully used OAuth for obtaining a sessionId for use with the API in Winter '10?

 

I've been able to get so far as to generate a valid OAuth access token, but I haven't yet been able to use that access token to get an API session id and I suspect the documentation may not be accurate or complete.

 

A few observations I've made: 

 

  • The documentation says the url is https://login.salesforce.com/services/OAuth/type/api-version.  Where type is "c" for the Partner WSDL and "u" for the enterprise WSDL.  This is the reverse of the normal SOAP API, and I assume it is a mistake, but can't verify since I can't get a session id.
  • The documentation says that "authorization header must have the following parameters" when referring to the request to obtain the session.  I take this to mean that one must use the Authorization HTTP header and not POST parameters to obtain the session id.  However, I've not had success with either.
  • If I do not use the authorization header and post the oauth parameters in the body, I get a response of LOGIN_OAUTH_INVALID_DSIG, indicating a bad signature.  Even though I'm using the same code to sign the request as I do for generating the request and access tokens.
  • If I instead use the Authorization HTTP header I get the error LOGIN_OAUTH_METHOD_NOT_SUPPORTED indicating I must use http POST, even though I already am.  Note, in this case the post body is empty.
 
If anybody has got this last step working it would be very helpful to know how you constructed the request.  Did you use the authorization header?  What were the contents of the POST?  Did you do anything special when generating your signature, in particular the generation of the OAuth Signature Base String and the key used for the signature (I'm using both the consumer and token secrets per the spec). 

 

Thanks,

 

George

 

  • October 22, 2009
  • Like
  • 0

Hi all

 

I am writing test cases for my Apex Page and want to verify that different messages are set at different points.

 

For this, I would like to clear out existing messages from my ApexPage.

 

Something similar to:

 

ApexPages.Messages = new List<ApexPages.Message>();


Is there a way to do this?

 

Hi,

 

I would like to parse the xml data as like below:

 

<AD_Client_ID><Label><![CDATA[Tenant]]></Label><Value>11</Value><Info><![CDATA[GardenWorld]]></Info><UniqueID><![CDATA[GardenWorld]]></UniqueID></AD_Client_ID><AD_Language><Label><![CDATA[Language]]></Label><Value><![CDATA[en_US]]></Value></AD_Language>

 

I wanted to parse this type of xml using XML DOM parser and I have to get  the value from <Info><![CDATA[GardenWorld]]></Info> and <Value><![CDATA[en_US]]></Value>.

 

 Please suggest me to parse the same.

 

If anyone of you have other idea to parse the above said xml, please inform me as early as possible. This is my urgent requirement. I hope for the suggestion or some sample code.

 

 Thanks in advance.

Message Edited by venkatesh on 04-06-2009 05:26 AM
Message Edited by venkatesh on 04-06-2009 08:15 AM
Hi All,
I am using HttpRequest and HttpResponse method to make an external call in Apex. But in HttpResponse I am not getting the proper result. I am getting the "Status=Object Moved" and "StatusCode=302". I understand this is because of "response.redirect" on the requested page. For this, I again get theURL for the redirected page and made a new request by setting the new EndPoint. But this time I am getting the "Session time out error".
This is because  both request has different session. Any idea how we can made multiple request with same session?


Thanks,
NG
  • October 09, 2008
  • Like
  • 0
Hi All,

I want Some doubt for Salesforce.com integreation with asp.net.

If any one help for me. How to integreate Salesforce.com with asp.net any one send for me sample working program...

I waiting for Favourable Reply for all.

With Regards,
K.Mani
Sofent technologies.
Hi,

I'm getting the following non-selective query error in one of my Apex triggers:

Error running cleanRecords method.Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

Here's the query statement ... isn't this selective?  I have WHERE and LIMIT clauses and put in hard-coded values for status and subject to make sure I wasn't passing in Null values.


Code:
for ( List<Task> tasks : [Select Id from Task where Status like 'Completed' 
and Subject like 'Delete Me'
and CreatedDate < :(System.now().addDays(0-days+1)) Limit 100]) { numDeleted += tasks.size(); delete tasks; }

Any help would be much appreciated.
 
Thanks,

Ron
The API seems to be lacking. The field IsPersonAccount is part of the Account but I get an error when I try to select it in my query against "Account".
Hi All,

I am looking for a PHP outbound messaging listener sample code. If someone can point me in the right direction. I would appreciate it very much.
  • August 22, 2008
  • Like
  • 0
hi,
 
I am using salesforce API to create accounts. I have a multiselect picklist to be selected with multiple items from .net code. In the API multiselect picklist is shown as a string type. Any help will be greatly apreciated.
 
 
Thanks,
Sandeep.
Appshark software pvt ltd.
 
Hi All,

    Good day. Is there a way to set the record type of a record to be saved via VF? Thanks!
I have created a Contact trigger that follows very closely to the cookbook Lead Duplicate Preventer code base.  It works fine and I have been able to deploy it to my production environment.  Now, I have some users that get the Query Exception error, and others that do not, even when adding the same new contact to the same account.  I can replicate this in both Dev and production, but can't figure out what the difference between users is, or what the user would have to do with the way the query executes.  I know the email field is not indexed, and that might be part of the problem, but am unclear as to why some users can execute successfully, and others get the error.  I hope that someone can help, and that this might be a good trigger that the entire SFDC Community can leverage.
Code is below!
Regards,
Jim Rae
 
 
Code:
TRIGGER CODE:

trigger ContactDuplicatePreventor on Contact (before insert, before update) {

    Map<String, Contact> ContactMap = new Map<String, Contact>();

    for (Contact contact : System.Trigger.new) {    

        // Make sure we don't treat an email address that
        // isn't changing during an update as a duplicate.

        if ((Contact.Email != null) && (System.Trigger.isInsert || (Contact.Email != System.Trigger.oldMap.get(Contact.Id).Email))) {
    
            // Make sure another new Contact isn't also a duplicate

            if (ContactMap.containsKey(Contact.Email)) {
                String errortext = 'Another new Contact has the same email address. ('+Contact.Email+') Please search for the existing Contact record with this address and update as appropriate, or contact your Administrator for assistance';
                Contact.Email.addError(errorText);
            } else {
                ContactMap.put(Contact.Email, Contact);
            }
        }
    }

    // Using a single database query, find all the Contacts in
    // the database that have the same email address as any
    // of the Contacts being inserted or updated.
 for(String test:ContactMap.keySet()){
 system.debug('\n\nContact added to Map was:'+test);  //only here for testing purposes
 system.debug('\n\nUser running trigger is:'+UserInfo.getUserName());
 system.debug('\n\n'+UserInfo.getProfileId());
 }
    for (Contact contact : [SELECT Email FROM Contact WHERE isDeleted = false and Email != null and Email IN :ContactMap.KeySet()]) {
        SYstem.debug('In the test loop');
        Contact newContact = ContactMap.get(Contact.Email);
  String errortext = 'Another Contact has the same email address. ('+newContact.Email+')  Please search for the existing Contact record with this address and update as appropriate, or contact your Administrator for assistance';
        newContact.Email.addError(errorText);
    }

TEST CASE CODE:
public class testBlockDuplicateContactEmails {
 
 static testMethod void testDuplicateContactEmailTrigger(){  
 
  //Creating all records against "Acme Corporation - HQ" Account (00100000002qK3l)
  Contact[] smith1 = new Contact[]{
   new Contact(  Email='smith@acme.org', LastName='Smith', Accountid='00100000002qK3l' )
  };
  insert smith1;  // add a known Contact
  
  Contact[] smith2 =new Contact[]{
   new Contact(  Email='smith@acme.org', LastName='Smith', Accountid='00100000002qK3l' )
  };
  // try to add a matching lead
  try {
   insert smith2;
   } catch (System.DmlException e) { 
   String errortext1 = 'FIELD_CUSTOM_VALIDATION_EXCEPTION, Another Contact has the same email address';
   system.debug('INSERT ERROR MESSAGE IS:'+e.getMessage());
   system.assert(e.getMessage().contains(errortext1), e.getMessage());
  }
  
  // test duplicates in the same batch for bulk Contact loading or lead conversion
  Contact[] bulkcontacts =new Contact[]{
   new Contact(  Email='Johnson@acme.org', LastName='Johnson', Accountid='00100000002qK3l' ),
   new Contact(  Email='Johnson@acme.org', LastName='Johnson', Accountid='00100000002qK3l' )
  };  
  try {
   System.debug('\n\n Insert Test');
    insert bulkcontacts;
    } catch ( System.DmlException e) { 
   String errortext2 = 'FIELD_CUSTOM_VALIDATION_EXCEPTION, Another new Contact has the same email address';   
   system.assert(e.getMessage().contains(errortext2), e.getMessage());
  }
  
  // test update also
  Contact[] contactup = new Contact[]{
   new Contact(  Email='jones@acme.org',  LastName='Jones', Accountid='00100000002qK3l' )
  };
  System.debug('\n\n Update Test');
  insert contactup;
  Contact updatetest = [ select id,Email from Contact where Email = 'jones@acme.org' and Accountid='00100000002qK3l' limit 1];
  system.assert(updatetest!=null);
  updatetest.Email = 'smith@acme.org'; 
    
  try { update updatetest; } catch ( System.DmlException e) { 
   String errortext3 = 'FIELD_CUSTOM_VALIDATION_EXCEPTION, Another Contact has the same email address';
   system.debug('UPDATE ERROR MESSAGE IS:'+e.getMessage());
   system.assert(e.getMessage().contains(errortext3), e.getMessage()); 
  }
  // Try a null email address
  Contact[] contactnull = new Contact[]{
   new Contact(  LastName='Anderson', Accountid='00100000002qK3l' )
  };
  System.debug('\n\n Null Test');
  try{ insert contactnull;} catch( System.DmlException e){
   system.debug('\n\nNull Insert ERROR MESSAGE IS:'+e.getMessage());
  }
  // Try a null email address Update
  Contact[] contactnull2 = new Contact[]{
   new Contact(  LastName='Anderson', Accountid='00100000002qK3l' )
  };
  System.debug('\n\n Null Update Test');
  insert contactnull2;
  Contact updatetest2 = [ select id,Email from Contact where Email=null and LastName = 'Anderson' and Accountid='00100000002qK3l' limit 1];
  system.assert(updatetest!=null);
  updatetest2.FirstName = 'Hans'; 
    
  try { update updatetest2; } catch ( System.DmlException e) { 
   system.debug('UPDATE ERROR MESSAGE IS:'+e.getMessage());
    
  }
 }
}

 
Where can I find the documentation on building the "regex_text" part of the REGEX function? All I can find in Help/Training/Release Notes is  a few examples of a working formula. There is nothing that explains the different characters and codes that can be used in the "regex_text" part of this function.
 
Syntax:
REGEX(text, regex_text)
 
Instructions:
Replace text with the text field, and regex_text with the regular expression you want to match
 
Examples:
REGEX(Drivers_License__c, "([A-Z]\\d{7})?")
REGEX(BillingPostalCode, "\\d{5}(-\\d{4})?")
REGEX(Credit_Card_Number__c, "(((\\d{4}-){3}\\d{4})|\\d{16})?")
REGEX(IP_Address__c, "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" )
REGEX(Social_Security_Number__c, "[0-9]{3}-[0-9]{2}-[0-9]{4}")
How can i get distinct elements from the database? Does SOQL not provide something like unique or distinct?