• wt35
  • SMARTIE
  • 528 Points
  • Member since 2011

  • Chatter
    Feed
  • 17
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 144
    Replies

I'm trying to use the containsNone function to rule out certain values.  It seems to not be working as designed.

 

Looking at the documentation, I'm assuming that the function will make sure that a certain substring is not present in the full string being tested.  What I think I'm seeing is that if ANY of the string, including a single letter, is present, the function will consider that string to be 'contained'.

 

For example, in the following snippet I want to rule out strings that have either MEM, XB or FTB in them.

 

 else if(newOpportunity.Amount > 250 &&
          (
            newOpportunity.Donation_Code__c.containsNone('MEM') &&
            newOpportunity.Donation_Code__c.containsNone('XB') &&
            newOpportunity.Donation_Code__c.containsNone('FTB')
          ) && ...
   

I did some testing and found that the following strings all got caught in this. (I expected only the second one to.)

 

  B, X, PPXBASSD, F T B (with spaces), F, MME

 

The strings that didn't get caught are:

 

  CCC, ZZZ, AAA, Y

 

I was going off of a workflow rule that used - does not contain (MEM, XB, FTB).  That worked fine.

 

Anyone else have similar problems with this?

         

Hi guys,

 

I'm fairly new to Salesforce and trying to do something pretty simple - update a field in a table which we have created using the Java SOAP API. Using SQL this would be something like:

 

UPDATE Custom_Employees__c

SET Leaving_Date__c='2013-09-04T17:50:45.000Z'

WHERE Employee_Number='0123456789'

 

Despite reading the SOAP API documentation and LOTS of googling I still cannot find any example code (and it looks like SOQL has no Update statement ???)

 

Can somebody please post a link or some example code?

 

Thanks in advance,

Marcus.

Hi,

 

I am new to Salesforce triggers. I want to populate the custom lookup "Contact Name" field on Opportunity screen whenever Lead gets converted.

 

Thanks,

SFBeginner

Hi,

 

First of all I have no Apex experience at all, and up until now havent needed any, so be kind! I have my sandbox built and have done some reading up on Apex language (last time I programmed  was PASCAL at college!)

 

I need to populate a custom lookup field on our Lead object based on it referencing a field on a custom object. As Leads can't be a child of a master-Child relationship, I've now realised the only way to do this will be an Apex trigger.

 

I've created a relationship between the Lead and custom object and now need the lookup field (CCLookup) on the Lead to use the value from Campaign Code (also on Lead) look up the value of the Field 'Campaign Code_CC' on my custom object and return the value of the custom object Name:

 

Campaign code on Lead: 1234

Campaign Code on custom Object: 1234

Name ID of Custom object: Campaign 1234

Lookup up field returns value of: Campaign1234

 

If no campaign code that matches exists on the custom object, the lookup field can remain blank.

 

Anyone willing to help!?

 

Antony

Hi, I am using standard detail page for detailed view of Order and its line items are listed in related list. In the related list of Line items, i can see standard Edit and Del Links against each record. I want to override Edit link to navigate to a new custom made detail page which will detail about the Line Item record for which the link was clicked. How can I retrieve the record Id of line item whos Edit link was clicked. Thanks, TechMighty

Hi,

 

how to display  the time and message  of latest post  in chatter in  vfpage?can anybody help on this ?

 

 

 

 

Hi all,

 

Could someone explain what the difference is (if there is any) between creating a new sandbox, and refreshing an existing sandbox? With regards to the resulting state of the sandbox. I haven't managed to find any information about this.

Mainly, I would like to know what happens to any data/apps in the sandbox after the refresh? E.g. are they all maintained, or deleted on refresh?

 

Thanks.

I am looking into Translation workbench and see how you translate fields, workflows etc.

 

However, is there a way to translate the section headers on a standard page layout as I don't see this option?

 

Many thanks

 

David 

Hi,

 

I have a question, when you first log in to SFDC and if you have any task reminders and pop up mini window happens. Is there any way to customize this to add fields related? Like name and phone number? As of now only this subject field shows up.

 

Please help.

 

Thanks so much,

SC

  • April 08, 2013
  • Like
  • 0

Hello!

 

I m working on import data from Salesforce. My boss asked to try to find three standard objects and import data from  them:

-Companies

-Contacts

-Location (a place, Latitude, Longitude, this kind of stuffs releated to locations)

 

I found Organization  and I suppose it's the company data. I also found Contact and I couldn t find any Object with data releated to Location.

 

I have two questions:

1) Is there a similiar standard object corresponding a location data?

2) Is there a relationship between Organization and Contact? I mean a foreign key like: these are all the contacts from this organization?

 

Thanks!

 

 

 

 

 

 

 

  • September 13, 2012
  • Like
  • 0

Hello All

 

I got some problem on triggers .I am try to send a group mails by using triggers on custom object.

 I got this error message"INVALID_TYPE_FOR_OPERATION, Only Users, Contact or Lead allowed for targetObjectId ".

 

Can't we send group mails on coustom object by using a triggers.PLZ help me any one in this problem.

 

my code:

 

 

trigger RoomExpensesTrig on Rooom_mets__c (after insert) {


if(trigger.isInsert&&trigger.isAfter) {
Rooom_mets__c con1=[Select id from Rooom_mets__c limit 1];


List<Rooom_mets__c> emailID = [select Email_id__c from Rooom_mets__c];

String addresses;
if (emailID[0].Email_id__c!= null) {

addresses = emailID[0].Email_id__c;

for (Integer i = 1; i < emailID.size(); i++){

if (emailID[i].Email_id__c != null)
{
addresses += ':' + emailID[i].Email_id__c;
}
}
}

String[] toAddresses = addresses.split(':', 0);


EmailTemplate et=[Select id from EmailTemplate where name=:'VFTmpToEmail'];

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses( toAddresses );
mail.setTargetObjectId(con1.Id);
mail.setSenderDisplayName('LAKSHMI3VENI');
mail.setTemplateId(et.id);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); 


}
}

  • August 31, 2012
  • Like
  • 0

A case is closed.  Later, the client replies back to an associated case email with a new issue.  The salesforce user is on vacation or no longer working in the call center.  The new email is now associated with the closed case and it goes unnoticed. 

 

I created an email workflow rule but with no success:

(Email Message: Is IncomingequalsTrue) and (Case: ClosedequalsTrue) to trigger a status change of the case object to "new" and owner to "queue."  Apparently, as the case object is not being saved, this rule won't work.
 
I assume this is a common problem and I've been scratching my head and searching for a solution.  Any help?
Thanks, Carl

 

 

Hi,

I am facing a apostrophe issue in my Visual force page.

I have a custom page which has a Account field which is a lookup, when the user clicks on the magnifying glass my custom Visual force page is opened. Everything works fine, except the time when a particular account has a name with an apostrophe.

I have written a javascript function that closes the popup as soon as the account is selected, the selected accounts name gets added in the text field on my main page.But when an apostrope is found the javascript function does not get callled at all.I have tried many approaches but did not get to a solution.

If anyone has come accross this issue then please let me know what needs to be done.

Thanks in advance!

 

Hi,

 

In one of Dataloader tutorial I got following point - 

 

If "Modifiable System Field" configuration is enabled, then system fields (like creation date) can be set to any value during initial data load. These values can however not be updated after the initial upload. These fields are accessible through the API. These are backward compatible with all SOAP based APIs available for all custom objects. These are Read only fields.

 

So, Is it possible to set initial value for system fields? If yes then Can anyone tell How to enable "Modifiable System Field" configuration for system fields? or  where I will found setting for system fields?

 

Thanks.

Hi all,

I am facing an issue in a before update trigger, I am just trying to add some characters at the end of a String field:

Trigger.new[0].myField__c  =  Trigger.new[0].myField__c  +  ',00' ;

The issue is that when I enter 12 in this field I should get 12,00.
However I get : 12,00,00

So it looks like my string is concatenated twice...could someone help?

Thanks!
  • January 15, 2014
  • Like
  • 0
Hi all,

Looking for some help on how to access a Custom Setting field with a String.

My use case is, I retrieve a month name as a string from a date eg. "January".
Thanks to that value I have to retrieve the value from the appropriate field in my Custom Setting instance (in this case January__c).

How can I convert my string to the metadata field name, knowing that these fields have the exact names + '__c'

Can anybody provide a snippet of code?

Thanks!



  • January 14, 2014
  • Like
  • 0

Hi Communtiy,

 

I can see that a class that I have developed implementing Batchable is available in the Apex Scheduler.

Is this normal?

 

I thought only Schedulable classes were available in that section.

 

Is there any difference with launching the batch job with Schedule methods?

 

Thanks

  • December 13, 2013
  • Like
  • 0

Hi Community,

 

I get this error while running my test class.

The test class only tests one method by providing an opportunity Id as parameter.

The debug log shows that the Opp Id is well transmitted to the method, 

 but then the SOQL Query against that Opp Id finds no results..

I appreciate your help...Thanks

 

 

Class:

 

 global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];

        Set<String> AuthorizedProfiles = new Set<String>();
        Set<String> AuthorizedOppOwner = new Set<String>();
        Set<String> TargetProducts = new Set<String>();
        AuthorizedProfiles.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_AuthorizedProfiles').split(';'));
        AuthorizedOppOwner.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_AuthorizedOppOwner').split(';'));
        TargetProducts.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_TargetProducts').split(';'));
        
        
        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
        
        System.debug ('#####################CONTEXTOPP ID: ' + contextOppId);
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
       System.debug ('#####################USERPROFILE NAME: ' + userProfile.Name);
       System.debug ('#####################CONTEXT OPP OWNER NAME: ' + contextOpp.Owner.Name);
        if (  AuthorizedProfiles.contains(userProfile.Name) &&        
                (contextOpp.Owner!=null && AuthorizedOppOwner.contains(contextOpp.Owner.Name)    )  
           )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c IN :TargetProducts
                /*Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')*/];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate!=null  &&  oppsToUpdate.size()>0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_StageWhenClosing');
                 o.Reason_For_Closed_Lost__c = GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_ReasonWhenClosing');
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

 

 

Test Class:

 

@isTest
public class CloseDuplicateOpportunitiesTest {


    static testMethod void test1() {
        
        Opportunity o1;
        Opportunity o2;
        User testUser;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='NA Telesales Rep']; 
        
        /*User oppOwner = new User(LastName='NA BS User', ProfileID=p.Id, Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='dwqwdwqdqwdwqdqwefewgfe@testorg.com');
        insert oppOwner;  */
          
        /*User u = new User(ProfileId = p.Id,Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='standarsafdewqfewfweFuser@testorg.com');*/
        
        User oppOwner = [SELECT Id,Name,ProfileId FROM User WHERE Name='NA BS User' LIMIT 1]; 
        User u = [SELECT Id,Name,Profile.Name,ProfileId FROM User WHERE Name='David Fabbro' LIMIT 1]; 
       
        User sysAdmin = TestMethodUtilities.getRunningUser();
        update sysAdmin ;
        
        System.runAs(sysAdmin ) {
        /*testUser  = TestMethodUtilities.getRunningUser();
        testUser.ProfileId=p.Id;
        update testUser;*/
                 
        Account a = new Account(Name='a',BillingCountry='IE');
        insert a;
        o1 = new Opportunity(Name='o1',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        o2 = new Opportunity(Name='o2',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        insert o1;
        insert o2;
      }
      
      
        System.runAs(u) {
        System.debug(o1.OwnerId);
        System.debug(oppOwner.Id);
        System.debug('#################### O1 ID: ' + o1.Id);
        String finalMessage = CloseDuplicateOpportunities.closeDuplicateOpportunities(o1.Id);
        System.assertEquals(finalMessage, '1 similar opportunities have been closed in addition to this one' );
      }
        
        
    
     }

}

 

Debug Log:

 

07:31:21.777 (18777718000)|USER_DEBUG|[42]|DEBUG|#####################CONTEXTOPP ID: 006S00000070NNuIAM
07:31:21.777 (18777726000)|SYSTEM_METHOD_EXIT|[42]|System.debug(ANY)
07:31:21.778 (18778087000)|SOQL_EXECUTE_BEGIN|[44]|Aggregations:0|select Id, AccountId, Owner.Name from Opportunity where Id = :tmpVar1
07:31:21.970 (18970619000)|SOQL_EXECUTE_END|[44]|Rows:0
07:31:21.972 (18972605000)|SYSTEM_METHOD_ENTRY|[46]|System.QueryException.getMessage()
07:31:21.972 (18972697000)|SYSTEM_METHOD_EXIT|[46]|System.QueryException.getMessage()
07:31:21.972 (18972723000)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY)
07:31:21.972 (18972741000)|USER_DEBUG|[46]|DEBUG|The following exception has occurred while trying to get the context opp: List has no rows for assignment to SObject
07:31:21.972 (18972750000)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY)
07:31:21.972 (18972788000)|SYSTEM_METHOD_ENTRY|[49]|System.debug(ANY)
07:31:21.972 (18972819000)|USER_DEBUG|[49]|DEBUG|#####################USERPROFILE NAME: NA Telesales Manager
07:31:21.972 (18972829000)|SYSTEM_METHOD_EXIT|[49]|System.debug(ANY)
07:31:21.972 (18972874000)|EXCEPTION_THROWN|[50]|System.NullPointerException: Attempt to de-reference a null object
07:31:21.972 (18972955000)|METHOD_EXIT|[64]|01pS0000000EZwQ|CloseDuplicateOpportunities.closeDuplicateOpportunities(Id)
07:31:21.972 (18972969000)|POP_TRACE_FLAGS|[64]|01pS0000000EZwQ|CloseDuplicateOpportunities|
07:31:21.983 (18983102000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.CloseDuplicateOpportunities.closeDuplicateOpportunities: line 50, column 1
Class.CloseDuplicateOpportunitiesTest.test1: line 64, column 1
07:31:21.983 (18983131000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

 

 

 

 

 

 

  • December 12, 2013
  • Like
  • 0

 

I get the following error when running my test class: 

Error Message System.NullPointerException: Attempt to de-reference a null object Stack Trace Class.CloseDuplicateOpportunities.closeDuplicateOpportunities: line 22, column 1
Class.CloseDuplicateOpportunitiesTest.test1: line 27, column 1

 

I have come across this error message several times in the past, bu t cannot understand why it happens here.

It looks like the Profile is not retrieved when my method is called by the test class.

I would like to point out that it works perfect when doing tests manually.

 

 

Test Class:

 

@isTest
public class CloseDuplicateOpportunitiesTest {

    @isTest(SeeAllData=true) static void test1() {
    
        //User oppOwner = [SELECT Id FROM User WHERE Name='NA BS User']; 

        Profile p = [SELECT Id FROM Profile WHERE Name='NA Telesales Rep']; 
        User oppOwner = new User(LastName='NA BS User', ProfileID=p.Id, Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='dwqwdwqdqwdwqdqwefewgfe@testorg.com');
        insert oppOwner;  
          
        User u = new User(ProfileId = p.Id,Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='standarsafdewqfewfweFuser@testorg.com');
        
        
        Account a = new Account(Name='a',BillingCountry='IE');
        insert a;
        Opportunity o1 = new Opportunity(Name='o1',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        Opportunity o2 = new Opportunity(Name='o2',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        insert o1;
        insert o2;
        
        System.runAs(u) {
        String finalMessage = CloseDuplicateOpportunities.closeDuplicateOpportunities(o1.Id);
        System.assertEquals(finalMessage, '1 similar opportunities have been closed in addition to this one' );
      }
        
        
    }






}

 

 

Class:

 

global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
   
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
        
        if (   (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('NA Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) && 
                contextOpp.Owner.Name == 'NA BS User' )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

Thanks!

  • December 10, 2013
  • Like
  • 0

Hi community,

 

I am getting this error while running a test class, I don't really understand why because I am not even trying to insert a user, only opportunities...

 

 

Error message:

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.<br>Another user has already selected this username.<br>Please select another.: [Username] Stack Trace Class.CloseDuplicateOpportunitiesTest.test1: line 17, column 1

 

 

 

Class:

 

global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
   
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
        
        if (   (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('NA Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) && 
                contextOpp.Owner.Name == 'NA BS User' )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

 

  • December 10, 2013
  • Like
  • 0

Hi community,

 

I get the here-above message when trying to update opportunities.


When looking at the API guide, it seems to be specific to Person Accounts errors but I do not have Person Accounts enabled.

I could also see other threads but did not get any help for my specific scenario.

 

Debug Log lines:

 

 

15:41:54.093 (93278000)|DML_BEGIN|[42]|Op:Update|Type:Opportunity|Rows:1
15:41:54.126 (126267000)|DML_END|[42]
15:41:54.126 (126412000)|EXCEPTION_THROWN|[42]|System.DmlException: Update failed. First exception on row 0 with id 006S00000070MRG; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Opportunity: bad field names on insert/update call: type: [type]
15:41:54.133 (133797000)|POP_TRACE_FLAGS|[EXTERNAL]|01pS0000000EZwQ|ClosedDuplicate|
15:41:54.204 (133826000)|CUMULATIVE_LIMIT_USAGE
15:41:54.204|LIMIT_USAGE_FOR_NS|(default)

 

Apex Class:

 

global class ClosedDuplicate{

   webService static String myMethod(Opportunity contextOpp) {
       
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
        if(contextOpp.Owner.Name == 'NA BS User') {}
        
        if ( /*  (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('Na Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) &&
                contextOpp.Owner.Name == 'NA BS User' */ true )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            oppsToUpdate.add(contextOpp);
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Product_Target__c INCLUDES ('Advanced','ECS','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }
                try{
                update oppsToUpdate;
                finalMessage = oppsToUpdate.size() + ' opportunities have been closed';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }

}

 

 

Thanks!!

 

 

 

  • December 09, 2013
  • Like
  • 0

Hi community,

 

I have a JavaScript button that calls successfully an Apex class.

However, now I want to give the Opportunity record as a parameter to my Apex method but it does not work.

(it is a detail page button)

When clicking on the button from the Opportunity, the message I get is:

 

"

A problem with the OnClick JavaScript for this button or link was encountered:
value is undefined

"

 

This is my JS button:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var opp = sforce.SObject("Opportunity");
var myString = sforce.apex.execute("ClosedDuplicate","myMethod2",{contextOpp:opp});


window.alert(myString);

 

Basically, what I am unable to do is transmit the opportunity record from where the button has been clicked to my Apex method. I hope its is possible. If not can someone give me the script for trasnmitting the record ID?

 

Thanks!

  • December 09, 2013
  • Like
  • 0

 I need to use the actionFunction tag to perform validation first in JS and then launch a controller method.

The controller method returns a new page reference.

 

However it seems my controller method is not called...

 

VF: ( I did not include validation yet as first I want the method call working)

 

<apex:page controller="HelloWorld">

<apex:form >

<apex:actionFunction name="myChange" action="{!change}" rerender=""/>
<apex:commandButton value="Warning" onclick="javascript&colon;confirmation();"/>

</apex:form>

<script>
function confirmation() {
     myChange();
}
</script>


</apex:page>

 

Apex method:

 

 

   public PageReference change(){
      System.debug('#######WORKS');
      PageReference pageRef = new PageReference('/apex/HelloWorld');
      pageRef.setRedirect(true);
      return pageRef;
      
   }

 

 

 

 

 

  • November 27, 2013
  • Like
  • 0

 

Hi community,

 

I have a button on which I want to include a warning message, that is, when the user clicks on the button, a message appears asking if he/she wants to continue...

 

This is where I have gotten so far, when I click on the button I do have the message popping up and asking if I want to continue, however the change() action is called even if I close this window...I want the processing to take place only if the user clicks OK...

 

Thanks you!

 

 

<apex:page controller="HelloWorld">

<apex:form >
<apex:commandButton value="Warning" onclick="javascript&colon;window.alert('Do you want to proceed?');" action="{!change}"/>
</apex:form>

</apex:page>

 

  • November 27, 2013
  • Like
  • 0

Hi Community 

 

I have an apex:commandButton that links to a JS function to open a new window.

The issue is that the link of the window that is referenced in the JS Function contains Global Variables, they do not merge as it is not VF Code. Can anybody suggest a solution?

 

My button:

 

<apex:commandButton value="MyButton" onclick="keyAccountData();return false;"/>

 

 

JS Function:

 

function keyAccountData() {
window.open('https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!$Api.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_250}&Id={!Account.Id}&DefaultPDF=1&DS7=3&LG4=1&LG3=2&OFN={!Account.Name}___OnePager_Onboard___{!NOW()}&TemplateId=a17Q0000001IguN&ReportId=00OQ0000000ThTh,00OQ0000000ThTX','Conga','height=175, width=300');
}

 

Or is it better to initialize the link in my controller?

 

Thanks!

  • November 21, 2013
  • Like
  • 0

Hi Community

 

I want to create a button in my VF page that opens a "New Case" page in Edit mode with a specific Record Type.

 

I have created the following button for this but nothing happens when clicking on it:

 

<apex:commandButton value="New Onboarding Action" onclick="parent.location.href='/500/e?def_account_id={!Account.Id}&RecordType={!recordTypeId}';"/>

 

Thanks for your help

  • November 18, 2013
  • Like
  • 0

Hi all,

 

I am trying to use the styleClass attribute to apply a specific style to a button but it doesn't work.

When I apply the same style inline in the tag it works.

 

The tag is <apex:commandButton>, any hint?

 

(I only managed so far  to modify the background colour of the button inline)

Thanks for explaining me what can be wrong in my code:

 

<apex:page >

    <style type="text/css"> 
      .myClass {
          color:white;
          background-color:#00CC00;
       }
    </style>
    

<apex:commandButton styleClass="myClass" action="{!someAction}">  
</apex:outputText>

</apex:page>
  • November 18, 2013
  • Like
  • 0

Hi all,

 

I am trying to use the styleClass attribute to apply a specific style but it doesn't work.

When I apply the same style inline in the tag it works.

 

Thanks for explaining me what can be wrong in my code:

 

<apex:page >

    <style type="text/css"> 
      .myClass {
          color:white;
          background-color:#00CC00;
       }
    </style>
    

<apex:outputText styleClass="myClass"> This should be white text with green background 
</apex:outputText>

</apex:page>

 

  • November 18, 2013
  • Like
  • 0

Hi all,

 

I am trying to get Record Type - Picklist Entries dynamically from Apex, does anybody know a way to achieve this?

 

To be more detailed, this is what I am trying to find out:

 

In Accounts, I have a Record Type called myRecordType.

I also have an account picklist called myPicklist, containing three values, only two of which are associated with myRecordType.

I want to use Apex to find out which are the two values associated to this record type, thanks to the Record Type and Picklist Name.

 

Thanks!

  • November 11, 2013
  • Like
  • 0

Hi all,

 

I am wondering if anybody has found a solution/approach to build custom Hover Links in Visualforce for a list of records.

What I mean by that is, I want the link to show on hover a custom list of records (list view/vf page/report),...belonging to the same account , just the same way as the standard Related List Hover Links does.

 

I know the LookupHoverDetail.getHover() method but that only works to display a single record.

 

Any hint is greatly appreciated.

 

Thanks!

  • October 29, 2013
  • Like
  • 0

Hello

 

I would like to know what is the API name of the table in which Files are stored.

I saw a table called Document but to me this one is obviously for files stored in  the Documents tab.

 

Thank you


Marc

  • September 10, 2012
  • Like
  • 0

Hello

 

I have a custom object for which I want to retrieve some field history.

For this I use the following SOQL query:

SELECT Field,NewValue,OldValue FROM Car__History

 

But it only pulls out the Field names, not the Old and New values, any ideas?

 

Thanks

  • August 31, 2012
  • Like
  • 0

Hello

 

I am new to the Flow Designer, just trying to set up a flow for new contact creation.

 

I want to include a search right a the beginning prompting the user to check whether the contact is already there or not.

 

Is that possible?

 

Thanks Marc

  • May 06, 2012
  • Like
  • 0

Hello,

 

I am trying to understand what the real difference is between those two, I have checked other posts but still cannot figure it out.

 

I thought that the Force.com environment provided just the platform without anything relating to Salesforce standard objects and automation. So I started a Force.com Enterprise trial and actually all the Salesforce stuff is already there, so I don't get it.

 

There's got to be a difference since the pricings are 125$ per user for SF against 50 for Force.com.

 

Could someone explain please?

 

Thank you

Marc

  • May 04, 2012
  • Like
  • 0
Hi all,

I am facing an issue in a before update trigger, I am just trying to add some characters at the end of a String field:

Trigger.new[0].myField__c  =  Trigger.new[0].myField__c  +  ',00' ;

The issue is that when I enter 12 in this field I should get 12,00.
However I get : 12,00,00

So it looks like my string is concatenated twice...could someone help?

Thanks!
  • January 15, 2014
  • Like
  • 0

Hi Communtiy,

 

I can see that a class that I have developed implementing Batchable is available in the Apex Scheduler.

Is this normal?

 

I thought only Schedulable classes were available in that section.

 

Is there any difference with launching the batch job with Schedule methods?

 

Thanks

  • December 13, 2013
  • Like
  • 0

Hi Community,

 

I get this error while running my test class.

The test class only tests one method by providing an opportunity Id as parameter.

The debug log shows that the Opp Id is well transmitted to the method, 

 but then the SOQL Query against that Opp Id finds no results..

I appreciate your help...Thanks

 

 

Class:

 

 global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];

        Set<String> AuthorizedProfiles = new Set<String>();
        Set<String> AuthorizedOppOwner = new Set<String>();
        Set<String> TargetProducts = new Set<String>();
        AuthorizedProfiles.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_AuthorizedProfiles').split(';'));
        AuthorizedOppOwner.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_AuthorizedOppOwner').split(';'));
        TargetProducts.addAll(GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_TargetProducts').split(';'));
        
        
        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
        
        System.debug ('#####################CONTEXTOPP ID: ' + contextOppId);
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
       System.debug ('#####################USERPROFILE NAME: ' + userProfile.Name);
       System.debug ('#####################CONTEXT OPP OWNER NAME: ' + contextOpp.Owner.Name);
        if (  AuthorizedProfiles.contains(userProfile.Name) &&        
                (contextOpp.Owner!=null && AuthorizedOppOwner.contains(contextOpp.Owner.Name)    )  
           )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c IN :TargetProducts
                /*Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')*/];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate!=null  &&  oppsToUpdate.size()>0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_StageWhenClosing');
                 o.Reason_For_Closed_Lost__c = GeneralUtil.getCodeVariableCustomSetting('CloseDuplicate_ReasonWhenClosing');
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

 

 

Test Class:

 

@isTest
public class CloseDuplicateOpportunitiesTest {


    static testMethod void test1() {
        
        Opportunity o1;
        Opportunity o2;
        User testUser;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='NA Telesales Rep']; 
        
        /*User oppOwner = new User(LastName='NA BS User', ProfileID=p.Id, Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='dwqwdwqdqwdwqdqwefewgfe@testorg.com');
        insert oppOwner;  */
          
        /*User u = new User(ProfileId = p.Id,Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='standarsafdewqfewfweFuser@testorg.com');*/
        
        User oppOwner = [SELECT Id,Name,ProfileId FROM User WHERE Name='NA BS User' LIMIT 1]; 
        User u = [SELECT Id,Name,Profile.Name,ProfileId FROM User WHERE Name='David Fabbro' LIMIT 1]; 
       
        User sysAdmin = TestMethodUtilities.getRunningUser();
        update sysAdmin ;
        
        System.runAs(sysAdmin ) {
        /*testUser  = TestMethodUtilities.getRunningUser();
        testUser.ProfileId=p.Id;
        update testUser;*/
                 
        Account a = new Account(Name='a',BillingCountry='IE');
        insert a;
        o1 = new Opportunity(Name='o1',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        o2 = new Opportunity(Name='o2',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        insert o1;
        insert o2;
      }
      
      
        System.runAs(u) {
        System.debug(o1.OwnerId);
        System.debug(oppOwner.Id);
        System.debug('#################### O1 ID: ' + o1.Id);
        String finalMessage = CloseDuplicateOpportunities.closeDuplicateOpportunities(o1.Id);
        System.assertEquals(finalMessage, '1 similar opportunities have been closed in addition to this one' );
      }
        
        
    
     }

}

 

Debug Log:

 

07:31:21.777 (18777718000)|USER_DEBUG|[42]|DEBUG|#####################CONTEXTOPP ID: 006S00000070NNuIAM
07:31:21.777 (18777726000)|SYSTEM_METHOD_EXIT|[42]|System.debug(ANY)
07:31:21.778 (18778087000)|SOQL_EXECUTE_BEGIN|[44]|Aggregations:0|select Id, AccountId, Owner.Name from Opportunity where Id = :tmpVar1
07:31:21.970 (18970619000)|SOQL_EXECUTE_END|[44]|Rows:0
07:31:21.972 (18972605000)|SYSTEM_METHOD_ENTRY|[46]|System.QueryException.getMessage()
07:31:21.972 (18972697000)|SYSTEM_METHOD_EXIT|[46]|System.QueryException.getMessage()
07:31:21.972 (18972723000)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY)
07:31:21.972 (18972741000)|USER_DEBUG|[46]|DEBUG|The following exception has occurred while trying to get the context opp: List has no rows for assignment to SObject
07:31:21.972 (18972750000)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY)
07:31:21.972 (18972788000)|SYSTEM_METHOD_ENTRY|[49]|System.debug(ANY)
07:31:21.972 (18972819000)|USER_DEBUG|[49]|DEBUG|#####################USERPROFILE NAME: NA Telesales Manager
07:31:21.972 (18972829000)|SYSTEM_METHOD_EXIT|[49]|System.debug(ANY)
07:31:21.972 (18972874000)|EXCEPTION_THROWN|[50]|System.NullPointerException: Attempt to de-reference a null object
07:31:21.972 (18972955000)|METHOD_EXIT|[64]|01pS0000000EZwQ|CloseDuplicateOpportunities.closeDuplicateOpportunities(Id)
07:31:21.972 (18972969000)|POP_TRACE_FLAGS|[64]|01pS0000000EZwQ|CloseDuplicateOpportunities|
07:31:21.983 (18983102000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.CloseDuplicateOpportunities.closeDuplicateOpportunities: line 50, column 1
Class.CloseDuplicateOpportunitiesTest.test1: line 64, column 1
07:31:21.983 (18983131000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

 

 

 

 

 

 

  • December 12, 2013
  • Like
  • 0

 

I get the following error when running my test class: 

Error Message System.NullPointerException: Attempt to de-reference a null object Stack Trace Class.CloseDuplicateOpportunities.closeDuplicateOpportunities: line 22, column 1
Class.CloseDuplicateOpportunitiesTest.test1: line 27, column 1

 

I have come across this error message several times in the past, bu t cannot understand why it happens here.

It looks like the Profile is not retrieved when my method is called by the test class.

I would like to point out that it works perfect when doing tests manually.

 

 

Test Class:

 

@isTest
public class CloseDuplicateOpportunitiesTest {

    @isTest(SeeAllData=true) static void test1() {
    
        //User oppOwner = [SELECT Id FROM User WHERE Name='NA BS User']; 

        Profile p = [SELECT Id FROM Profile WHERE Name='NA Telesales Rep']; 
        User oppOwner = new User(LastName='NA BS User', ProfileID=p.Id, Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='dwqwdwqdqwdwqdqwefewgfe@testorg.com');
        insert oppOwner;  
          
        User u = new User(ProfileId = p.Id,Alias = 'standt', Email='standarduser@testorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', TimeZoneSidKey='America/Los_Angeles', UserName='standarsafdewqfewfweFuser@testorg.com');
        
        
        Account a = new Account(Name='a',BillingCountry='IE');
        insert a;
        Opportunity o1 = new Opportunity(Name='o1',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        Opportunity o2 = new Opportunity(Name='o2',CloseDate=System.Today(),AccountId=a.Id,OwnerId=oppOwner.Id,StageName='Engaged',Product_Target__c='Advanced');
        insert o1;
        insert o2;
        
        System.runAs(u) {
        String finalMessage = CloseDuplicateOpportunities.closeDuplicateOpportunities(o1.Id);
        System.assertEquals(finalMessage, '1 similar opportunities have been closed in addition to this one' );
      }
        
        
    }






}

 

 

Class:

 

global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
   
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
        
        if (   (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('NA Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) && 
                contextOpp.Owner.Name == 'NA BS User' )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

Thanks!

  • December 10, 2013
  • Like
  • 0

Hi community,

 

I am getting this error while running a test class, I don't really understand why because I am not even trying to insert a user, only opportunities...

 

 

Error message:

 

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_USERNAME, Duplicate Username.<br>Another user has already selected this username.<br>Please select another.: [Username] Stack Trace Class.CloseDuplicateOpportunitiesTest.test1: line 17, column 1

 

 

 

Class:

 

global class CloseDuplicateOpportunities{

   webService static String closeDuplicateOpportunities(Id contextOppId) {
       
        Opportunity contextOpp;
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
   
        try{
        contextOpp = [SELECT Id,AccountId,Owner.Name FROM Opportunity WHERE Id=:contextOppId];
        } catch(Exception e){
        System.debug('The following exception has occurred while trying to get the context opp: ' + e.getMessage());
        }
        
        
        if (   (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('NA Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) && 
                contextOpp.Owner.Name == 'NA BS User' )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            
            oppsToUpdate.add(contextOpp);
                       
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Id != :contextOpp.Id AND 
                Product_Target__c INCLUDES ('Advanced','Express Checkout Shortcut (ECS)','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }

                System.debug('###########oppsToUpdate '+ oppsToUpdate);
                try{
                update oppsToUpdate;
                finalMessage = relevantOpps.size() + ' similar opportunities have been closed in addition to this one';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }


}

 

 

 

  • December 10, 2013
  • Like
  • 0

global class MainClass
{
global class RequestClass
{
webservice String errorMessage;

//Account Releated Fields

global Class AccountWrapper // Line9
{
webservice String accName;
webservice Integer accNumber;
webservice Id AccountId;
webservice List<AccountWrapper> accounts;
webservice List<ContactWrapper>;
webservice List<OpportunityWrapper>;
}

//Contact Releated Fields
//webservice String contactName;
global class ContactWrapper
{
webservice String clName;
webservice String cfName;

}

// Opportunity Releated Fields
global class OpportunityWrapper
{
webservice String oName;
webservice String ocDate;
webservice String oStage;
webservice List<ProductWrapper>;
}
// Quote Realeted Fields
webservice String qName;




// Product fields
global class ProductWrapper
{
webservice String productcode;
webservice String productName;
// boolean active;
webservice Integer quantity;
webservice Integer unitprice;
}
// QuoteItem Fields

webservice String qitemName;


}

webservice static ResponseClass behaviourOfWebService(RequestClass req)
{

List<Account> accountList = new List<Account>();
Account a;
for(AccountWrapper wrapper: req.accounts){
a = new Account();
a.Name = wrapper.accName;
a.AccountNumber =String.valueOf(wrapper.accNumber);
accountList.add(a);
}
insert AccountList;

ResponseClass res = new ResponseClass();
res.resId = a.Id;
res.resName = a.Name;
res.cresName = c.FirstName;
// res.respId = p.Id;
return res;
return res;

}

Hi community,

 

I get the here-above message when trying to update opportunities.


When looking at the API guide, it seems to be specific to Person Accounts errors but I do not have Person Accounts enabled.

I could also see other threads but did not get any help for my specific scenario.

 

Debug Log lines:

 

 

15:41:54.093 (93278000)|DML_BEGIN|[42]|Op:Update|Type:Opportunity|Rows:1
15:41:54.126 (126267000)|DML_END|[42]
15:41:54.126 (126412000)|EXCEPTION_THROWN|[42]|System.DmlException: Update failed. First exception on row 0 with id 006S00000070MRG; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Opportunity: bad field names on insert/update call: type: [type]
15:41:54.133 (133797000)|POP_TRACE_FLAGS|[EXTERNAL]|01pS0000000EZwQ|ClosedDuplicate|
15:41:54.204 (133826000)|CUMULATIVE_LIMIT_USAGE
15:41:54.204|LIMIT_USAGE_FOR_NS|(default)

 

Apex Class:

 

global class ClosedDuplicate{

   webService static String myMethod(Opportunity contextOpp) {
       
        List<Opportunity> relevantOpps;
        String finalMessage;
        Profile userProfile = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];


        /*********************************************************/
        /*****************AUTHORIZED USER ************************/
        /*********************************************************/
        if(contextOpp.Owner.Name == 'NA BS User') {}
        
        if ( /*  (userProfile.Name.equals('NA Telesales Rep') ||
                userProfile.Name.equals('Na Telesales Manager') ||
                userProfile.Name.equals('NA Territory Manager - Outbound')) &&
                contextOpp.Owner.Name == 'NA BS User' */ true )
        {
            List<Opportunity> oppsToUpdate = new List<Opportunity>();
            oppsToUpdate.add(contextOpp);
            try{
            relevantOpps = [SELECT Id,StageName,Reason_For_Closed_Lost__c FROM Opportunity WHERE 
                AccountId = :contextOpp.AccountId AND
                IsClosed = false AND
                Owner.Name like 'NA BS User' AND
                Product_Target__c INCLUDES ('Advanced','ECS','Pro')];
            oppsToUpdate.addAll(relevantOpps);
            } catch(Exception e){
            finalMessage = 'No relevant opportunities have been closed because either none were found or an error has happened.';
            }

            if(oppsToUpdate.size() > 0)
            {
                for (Opportunity o : oppsToUpdate)
                {
                 o.StageName = 'Closed Lost';
                 o.Reason_For_Closed_Lost__c = 'Close - TS Duplicate';
                }
                try{
                update oppsToUpdate;
                finalMessage = oppsToUpdate.size() + ' opportunities have been closed';
                } catch(Exception e){
                finalMessage = 'No relevant opportunities have been closed';
                }
            }
            
        } 
           


        /*********************************************************/
        /********************NON-AUTHORIZED USER *****************/
        /*********************************************************/
        else{            
            finalMessage = 'No relevant opportunities have been closed because you do not have an authorized profile or the opportunity is not owned by NA BS User.';
        }


     return finalMessage;
    }

}

 

 

Thanks!!

 

 

 

  • December 09, 2013
  • Like
  • 0

Hi community,

 

I have a JavaScript button that calls successfully an Apex class.

However, now I want to give the Opportunity record as a parameter to my Apex method but it does not work.

(it is a detail page button)

When clicking on the button from the Opportunity, the message I get is:

 

"

A problem with the OnClick JavaScript for this button or link was encountered:
value is undefined

"

 

This is my JS button:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var opp = sforce.SObject("Opportunity");
var myString = sforce.apex.execute("ClosedDuplicate","myMethod2",{contextOpp:opp});


window.alert(myString);

 

Basically, what I am unable to do is transmit the opportunity record from where the button has been clicked to my Apex method. I hope its is possible. If not can someone give me the script for trasnmitting the record ID?

 

Thanks!

  • December 09, 2013
  • Like
  • 0

 I need to use the actionFunction tag to perform validation first in JS and then launch a controller method.

The controller method returns a new page reference.

 

However it seems my controller method is not called...

 

VF: ( I did not include validation yet as first I want the method call working)

 

<apex:page controller="HelloWorld">

<apex:form >

<apex:actionFunction name="myChange" action="{!change}" rerender=""/>
<apex:commandButton value="Warning" onclick="javascript&colon;confirmation();"/>

</apex:form>

<script>
function confirmation() {
     myChange();
}
</script>


</apex:page>

 

Apex method:

 

 

   public PageReference change(){
      System.debug('#######WORKS');
      PageReference pageRef = new PageReference('/apex/HelloWorld');
      pageRef.setRedirect(true);
      return pageRef;
      
   }

 

 

 

 

 

  • November 27, 2013
  • Like
  • 0

 

Hi community,

 

I have a button on which I want to include a warning message, that is, when the user clicks on the button, a message appears asking if he/she wants to continue...

 

This is where I have gotten so far, when I click on the button I do have the message popping up and asking if I want to continue, however the change() action is called even if I close this window...I want the processing to take place only if the user clicks OK...

 

Thanks you!

 

 

<apex:page controller="HelloWorld">

<apex:form >
<apex:commandButton value="Warning" onclick="javascript&colon;window.alert('Do you want to proceed?');" action="{!change}"/>
</apex:form>

</apex:page>

 

  • November 27, 2013
  • Like
  • 0