• Boom B OpFocus
  • NEWBIE
  • 285 Points
  • Member since 2013
  • OpFocus

  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 47
    Replies
The Contact Role object can not have fields added to it.  In order to get around this I have created a custom object  with an Object Name= OpportunityContactRoles and gave it a child relationship to the opportunity object.  The custom object has the two fields that are on the Contact Role object, ContactID and Object Name Parts (same as Role), but also has additional fields on it.

What I would like to have happen is every time a Contact name and Parts has been entered into the custom object and saved, a new  standard Contact Role is automatically created on the opportunity with the same Contact name and Role (Parts).  Can anyone help me with a trigger and class for this?  So far I have this but I know it's not even close.


trigger new_Contact_Role_to_Standard on Contact Role
{
   for(Contact Role c : Trigger.New)
   {
        OpportunityContactRole o = new OpportunityContactRole;
        o.ContactId = set the contact id here;
        o.OpportunityId = set the Opportunity id here;
        insert o;
   }
}
I am really new at apex code and worse at trying to do the test coverage. My code is only at 65% and I'm at a loss at what else do to. Can anyone help please.

Here is my current test code and my trigger is below that.
The Test Code: Coverage only at 65%
@IsTest Private class TestSRProducts {
   
    testMethod private static void getthedata() {
        // Create the user
       // User testUser = NewObjFactory.buildTestUser(0, 'Pipo', 'Tanya');
       // insert testuser;
        String PM7 = 'Tanya Pipo';
        User testuser = [Select ID, Name
                     From User
                     Where Name = :PM7];
        system.debug('User ' +testuser.id);
      
      
   
        // Create the Account
        Account testacct = NewObjFactory.buildTestAcct(0, 'User - IT', testuser.id);
        insert testacct;
       
       
        // Create the Contact
        Contact testcontact = NewObjFactory.buildTestContact(0, testacct.id, testuser.id);
        insert testcontact;
      
       
        // Create a product
        Product2 testprod = NewObjFactory.buildTestProducts(0);
        insert testprod;
        Product2 testprod2 = NewObjFactory.buildTestProd2(0);
        insert testprod2;
      
       
        // Create a Stocking Request
        Stocking_Request__c testSR = NewObjFactory.buildTestStockingReq(0, testacct.id, testuser.id, testcontact.id);
        insert testSr;
        system.debug('SR ' +testsr.id);
       
        // Create a SR Product and envokes the trigger
        SR_Products__C testsrprod = NewObjFactory.buildtestSRProducts(0, testSR.id);
        SR_Products__C testsrprod2 = NewObjFactory.buildtestSRProducts(0, testSR.id);
        testsrprod2.Product__c = [Select ID from Product2 where name = :'CLS2PAP SHEET SECONDS GLOSS'].id;
        Test.startTest();
        insert testsrprod;
        insert testsrprod2;
        Test.stopTest();
       
        Stocking_Request__c SR1 = [Select ID, Name, product_manager_1__c,
                     product_manager_2__c, product_manager_3__c, product_manager_4__c,
                     product_manager_5__c, product_manager_6__c, product_manager_7__c, product_manager_8__c
                     From Stocking_Request__c
                     Where ID = :testsr.id];           
            If (SR1 != null){
       
         system.debug('product manager is '+SR1.name);
         system.debug('product manager7 is '+ SR1.product_manager_7__c);
          }
        System.assertEquals (SR1.product_manager_7__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_6__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_5__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_4__c, testuser.id);
        System.assertNOtEquals (SR1.product_manager_3__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_2__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_1__c, testuser.id);
       
   
    }    //End getthedata
       
       
} //End Class TestSRProducts
The trigger:

trigger SR_Set_Approvers on SR_Products__c (After insert, After Update) {
   
    // This trigger sets all the product managers from the Stocking Request records
    // With the data from the SR - Product Details records
   
    // Loop all product records that have changed
    for (SR_Products__c prod : Trigger.new) {
       
        // system.debug('product name1 = ' + prod.Stocking_Request__c);
        // Get all the product records related to the SR
        SR_Products__c[] allproducts = [SELECT product_manager__c, PM_Type__C,
                                        stocking_request__c
                            FROM SR_Products__c
                            WHERE stocking_request__c = :Prod.stocking_request__c 
                            ];
        String Pm1 = '';
        String Pm2 = '';
        String Pm3 = '';
        String Pm4 = '';
        String Pm5 = '';
        String Pm6 = '';
        String Pm7 = '';
        String Pm8 = '';
            //Set the PM variables with the PM from the SR-Products records       
        for(SR_Products__c p : allproducts) {
       
            If (p.PM_Type__c == 'PM1')
                pm1 = p.product_manager__c;
            If (p.PM_Type__c == 'PM2')
                pm2 = p.product_manager__c;
            If (p.PM_Type__c == 'PM3')
                pm3 = p.product_manager__c;
            If (p.PM_Type__c == 'PM4')
                pm4 = p.product_manager__c;
            If (p.PM_Type__c == 'PM5')
                pm5 = p.product_manager__c;
            If (p.PM_Type__c == 'PM6')
                pm6 = p.product_manager__c;
            If (p.PM_Type__c == 'PM7')
                pm7 = p.product_manager__c;
            If (p.PM_Type__c == 'PM8')
                pm8 = p.product_manager__c;                   
        } //end loop products
       
        // Get the Stocking Request record
        //system.debug('product name = ' + prod.Stocking_Request__c);
        Stocking_Request__c sr = [Select ID, Name,
                               Product_Manager_1__c, Product_Manager_2__c,
                               Product_Manager_3__c, Product_Manager_4__c,
                               Product_Manager_5__c, Product_Manager_6__c,
                               Product_Manager_7__c, Product_Manager_8__c
                     From Stocking_Request__c
                     Where ID = :prod.Stocking_Request__c];
       
        // Reset all PM fields to blank to start out with
        sr.Product_Manager_1__c = null;
        sr.Product_Manager_2__c = null;
        sr.Product_Manager_3__c = null;
        sr.Product_Manager_4__c = null;
        sr.Product_Manager_5__c = null;
        sr.Product_Manager_6__c = null;
        sr.Product_Manager_7__c = null;
        sr.Product_Manager_8__c = null;
        // Get the user record IDs for the PM variable fields
        // And set the PM fields in the stocking request record
     
        If (PM1 != '' ){
            User u1 = [Select ID, Name
                     From User
                     Where Name = :PM1];           
            If (u1 != null)sr.Product_Manager_1__c = u1.ID;
        } //End PM1 if
       
      
        If (PM2 != '' ){
            User u2 = [Select ID, Name
                     From User
                     Where Name = :PM2];
            If (u2 != null)sr.Product_Manager_2__c = u2.id;
        } //End PM2 if       
      
        If (PM3 != '' ){
            User u3 = [Select ID, Name
                     From User
                     Where Name = :PM3];
            If (u3 != null)sr.Product_Manager_3__c = u3.id;
        } //End PM3 if
       
        If (PM4 != ''){
            User u4 = [Select ID, Name
                     From User
                     Where Name = :PM4];
            If (u4 != null)sr.Product_Manager_4__c = u4.id;
        } //End PM4 if       
      
        If (PM5 != '' ){
            User u5 = [Select ID, Name
                     From User
                     Where Name = :PM5];
            If (u5 != null)sr.Product_Manager_5__c = u5.id;
        } //End PM5 if       
       
        If (PM6 != ''){
            User u6 = [Select ID, Name
                     From User
                     Where Name = :PM6];
            If (u6 != null)sr.Product_Manager_6__c = u6.id;
        } //End PM6 if       
 
        If (PM7 != '' ){
            User u7 = [Select ID, Name
                     From User
                     Where Name = :PM7];
           
            If (u7 != null)sr.Product_Manager_7__c = u7.id;
        } //End PM7 if       
           
        If (PM8 != '' ){
            User u8 = [Select ID, Name
                     From User
                     Where Name = :PM8];
            If (u8 != null)sr.Product_Manager_8__c = u8.id;
        } //End PM8 if
              
       Update sr;
      
    }  // End for looping of changed product records
}
Hello All,

I am having an issue when trying to convert leads. We need to be able to enter the email, phone and address on the account record as well as the contact record. The issue is they are standard fields and when the account or contact already exists it does not override the existing information on the records if they are not blank.

I wanted to know if it was possible to make sure that these fields always override the values through the use of apex code without trying to create hidden fields with workflow rules. I need for the standard email, phone and address fields to always enter in the newly converted information to the records even if they already exist and contain data.

If this is possible with Apex Code does anyone have a snippet that shows how to do this with just one field? If so, could you post an answer to this question? Any help would be tremendously appreciated.

Respectfully,
Scott
Hi,
I have a scenario, where i have 2 users 'a'&'b' with same profile.
For user 'a' i have a validation rule to stop any modifications in the opportunity details section once it is saved.
But the user must have the access to add the line items once added to the opportunity team.
If i add 'a' in an opportunity team and give him read/write access, when he tries to modify any field, the validation rule is triggered and gets an error.
But the validation rule prevents the user from adding the line items also.

Is there any way we can keep the validation rule only for the opportunity details, not for any related list objects.

My validation rule is 
AND( Id <> null, $User.Horizontal_User__c == true).

Its very urgent.

Any help is appreciated.

Thanks.

We currently have a workflow that creates a "dummy" email address when an email address is not provided in a lead or contact record. The business requirement is for the email address to be FirstName.LastName@Company.nomail. The problem we're running into is that the email fields do not like any spaces in the email address, which is a problem for company's with multiple words in their name.. i.e. Some Burger Corp. Contact names also cause the same issue.

 

The workflow uses a simple formula to set the value: FirstName +"."+ LastName +"@"+ Company +"."+ "nomail"


Is there a way to remove all white spaces in a concatenation formula?

 

Thanks for you help.

I have a trigger that updates opportunity amount based on a field from a custom object (Proposal). I need to modify this trigger to only perform this field update if custom field Apttus_Proposal__Primary__c (checkbox) is checked. Can someone please help me with where in this trigger I need to define this? 

 

Trigger updteopp_Amount on Apttus_Proposal__Proposal__c (after update, after insert) {

Map<id,Decimal> varmap=new Map<id,Decimal>();

List<Opportunity> opp=new List<Opportunity>();

if(Trigger.isupdate){

for(Apttus_Proposal__Proposal__c App:Trigger.New){

if(Trigger.NewMap.get(App.id).Total_Quote_Amount_2__c!=null ){

varmap.put(App.Apttus_Proposal__Opportunity__c,App.Total_Quote_Amount_2__c); //Apttus_Proposal__Opportunity__c put ur lookup which is onto opportunity

}

}

if(!varmap.IsEMpty()){

List<Opportunity> opps=[select id,name,Amount from opportunity where id in:Varmap.keyset()];

if(!opps.isEmpty()){

for(Opportunity o:opps){

o.Amount=varmap.get(o.id);

opp.add(o);

}

database.update(opp);

}

}

}

}

Hi,

 

I have some reports in my org which I only want some users to see. I have created a folder and a public group with those users and shared the folder with the group. It works fine for most of the users.However I found that some users were still able to access this reports. I mean they are not getting the Insufficient privileges error. They can see the report and edit the report. They are not seeing any data on the report.

 

Why is this happening? My guess is its a profile permission. But I cannot figure out which one.Can somebody please explain?

 

Thanks in advance.

  • September 06, 2013
  • Like
  • 0

I want to create a custom application that has an i-frame inside of the Salesforce contact tab. Basically whenever a CRM user accesses one of their contacts, they will see all of the usual fields from the Contacts tab plus my i-frame.

 

I tried editing the Contacts tab but was not able to figure out where to click to change the VisualForce.

 

Does Salesforce not allow me to edit their contacts tab? Do I need to create a custom tab inorder to add in the i-frame?

 

thanks in advance,

Nick

I created a custom object and can't see it under the + tab.  The object is deployed and my ID has full rights to it (verified the profile settings).

 

Any ideas?

  • June 25, 2013
  • Like
  • 0

I wrote a Trigger on Lead that creates an Opportunity Team Member when a Lead is converted and it has ConvertedOpportunityId.  The Opportunity Team Member should have UserId = Lead OwnerId and has a specific role (for example - "Account Manager").  

 

I tested converting a Lead that was owned by me and the Opportunity was created with an Opportunity Team Member = me and role was Account Manager, so I thought the Trigger worked fine.  Then I tested converting a Lead that was owned by another user.  The Opportunity was created with the same owner as the Lead Owner, but there was no Opportunity Team Member.  I added some debug statements to catch if the Opportunity Team Member was really created and it did (at least) in the debug log.  One of the debugs showed that the Opportunity Team Member was created from the Trigger and it had me (the person who converted the Lead) as the Member.  Another debug showed that I was the Opportunity Owner, but when I checked in the UI, the Opportunity Owner was actually the other user.  

 

Here is my Lead Trigger.

Trigger Lead on Lead (before insert, before update) {
	 	
	if (Trigger.isBefore) {
		
		if (Trigger.isUpdate) {	
					
			Set<Id> setLeadIds     = new Set<Id>();  
			Set<Id> setConvertedOppIds   = new Set<Id>();  
			
			for (Lead ld : Trigger.new) {

				// Find all converted Leads with Opportunitiy and add ConvertedOpportunityId to setConvertedOppIds
				if (ld.isConverted && ld.ConvertedOpportunityId != null 
					&& Trigger.oldMap.get(ld.Id).ConvertedOpportunityId != ld.ConvertedOpportunityId) 
					setConvertedOppIds.add(ld.ConvertedOpportunityId);			
			}		

			if (!setConvertedOppIds.isEmpty()) {
				List<OpportunityTeamMember> lstOppTeams = new List<OpportunityTeamMember>();
				// Get Opportunities that created from the Lead conversion
				List<Opportunity> lstConvertedOpps = [select Id, OwnerId from Opportunity where Id in :setConvertedOppIds];
				if (lstConvertedOpps.size() > 0) {					
					for (Opportunity opp : lstConvertedOpps) {
						OpportunityTeamMember otm = new OpportunityTeamMember(
								   TeamMemberRole = 'Account Manager', 
						           OpportunityId  = opp.Id,
						           UserId         = opp.OwnerId);
						lstOppTeams.add(otm);
					}
					// Insert Opportunity Team
					if (!lstOppTeams.isEmpty()) {
						for (Opportunity opp : lstConvertedOpps) {
							System.debug('===== before inserting OTMs, opp = ' + opp);
						}
						System.debug('===== inserting OTMs: ' + lstOppTeams);
						
						insert lstOppTeams;
						
						for (OpportunityTeamMember otm : [select id, UserId, TeamMemberRole from OpportunityTeamMember where OpportunityId in :setConvertedOppIds])
							System.debug('===== OTM after insert: ' + otm);
						
						lstConvertedOpps = [select Id, OwnerId from Opportunity where Id in :setConvertedOppIds];
						for (Opportunity opp : lstConvertedOpps) {
							System.debug('===== after inserting OTMs, opp = ' + opp);
						}
					}
				}
			}
		}		
	} 	
}

 

 

So, I wonder if we can really write a Trigger on Lead that creates an Opportunity Team Member that belongs to a different user?

Also, can we catch what happens during the Lead Conversion, like why there seems to be some opportunity owner changing during that time but we couldn't really see that?

 

Out of the curiousity, I wrote a Trigger on Opportunity just for debug to see if I could catch the opportunity change.  Strangely, I was unable to do that.  The debugs only showed that I was the opportunity owner right before Insert and also after insert.  Nothing showed that the other user was the opportunity owner until I checked in the UI.

 

Here is the opportunity Trigger.

Trigger Opportunity on Opportunity (after insert, after update, before insert, before update) {

	String str = '';
	str += (Trigger.isBefore) ? 'Before ' : 'After ';
	if (Trigger.isInsert) str += 'Insert: ';
	if (Trigger.isUpdate) str += 'Update: ';

	for (Opportunity opp : Trigger.new) {
		System.debug('===== ' + str + ' Opp Id=' + opp.id + '   OwnerId=' + opp.OwnerId);
	}

}

 

I uploaded a package to AppExchange (in my private listing) and just realized that I didn't want "Contact Layout" and "Lead Layout" to be in my package.  I went to the Developer org to removed those page layouts from the managed package, but there wasn't a remove option on either page layout in the package components.

 

There is no Profile in the package and the page layouts are not being used in the custom settings in the package.  So, I don't think they depend on any components in the package.  

 

Why can't I remove the page layouts?  Please help.

 

 

Hi,

I am trying to bulkify this trigger..But when i load more produtcs i still get error ...So i need to bulkify this trigger more...Please help!!!!

trigger StandardPriceupdate on Product2 (after insert,after update) {
 
  List<Pricebook2> listPricebook = new List<Pricebook2>();
  List<PricebookEntry> listPricebookEntry = new List<PricebookEntry>(); 
  List<PricebookEntry> listupdPBentry = new List<PricebookEntry>();
  List<PricebookEntry> listinsPBentry = new List<PricebookEntry>();
  List<Product2> listProducts = new List<Product2>();
  Public boolean PricebookCheck = False;
 
   listPricebook = [SELECT IsActive, Description, IsStandard, Id, Name FROM Pricebook2 where Name =: 'Standard Price Book'];
   listPricebookEntry = [SELECT UnitPrice, Id, Pricebook2Id, ProductCode, Product2Id, Name, SystemModstamp, UseStandardPrice, IsActive FROM       PricebookEntry where Pricebook2Id =: listPricebook[0].Id];

   for(Product2 objProduct : System.Trigger.New) {
      listProducts.add(objProduct);      
   }
   
    for(Product2 Prod : listProducts){
      for(PricebookEntry PbEntry : listPricebookEntry){
            if(PbEntry.Product2Id == Prod.id){
             PbEntry.Unitprice = Prod.Std_PB_List_Price__c;
             listupdPBentry.add(PbEntry);
             PricebookCheck = True;
             }           
        }
        if(PricebookCheck != True){
            PricebookEntry insPBentry = new PricebookEntry (IsActive = True, UnitPrice = Prod.Std_PB_List_Price__c, Pricebook2Id =listPricebook[0].Id, Product2Id =Prod.Id);
            listinsPBentry.add(insPBentry);       
        }
        PricebookCheck = False;      
    }     
    
    if(listupdPBentry.size()>0){
     update listupdPBentry;
    }
    if(listinsPBentry.size()>0){
     insert listinsPBentry;
    }

}
I have created a Package that is managed released. And i have installed it on other dev org. My all the classes and pages are functioning well but i am getting some error in one of my page.

I got why it is giving error. Now i have to do some modification in the one of the class in the Org where i created the managed released package and i did that. But my question is now.
1) How will i fix these changes in the installed org?
2) Do i will have to create another released or i can do it by patch or push?
3) If can do it through patch and push upgrades then how?

I am confused what to do next. Please give me some information so that i could go ahead.
I want to update a field on account based on the list of tasks that are remaining after deleting a task from Account. The value is being populated from Task or list of task which is remained on account after deleting a task. How to achieve it because trigger.new doesnt work on delete operation and trigger.old will include the value of that task also , which i want to delete. Please help.




Thanks in advance
I am trying to add the opportunity object to this following code. I need the trigger to insert the opportunity Id (OppId__c) on the custom object Survey__c. This is what i have for my trigger code. Also,  when i try filling out the survey  I get the following error.

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Trigger_SurveyAfterInsert: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.Trigger_SurveyAfterInsert: line 8, column 1: []
Error is in expression '{!insertSurvey}' in component <apex:commandButton> in page vf_sales_survey: Class.VFController_survey_opps.insertSurvey: line 44, column 1


TRIGGER CODE:
trigger Trigger_SurveyAfterInsert on Survey__c (after insert) {
    for(Survey__c event: System.Trigger.New){
        List<Survey__c> lobjects;
        string name;
        lobjects = [select Id, Case__c, CaseId__c,Opportunity__c,OppId__c from Survey__c where Id=:event.Id];
        if(lobjects.size() == 1){
            Survey__c srv = lobjects[0];
            Case cs = [select Id, AccountId, ContactId, Service_Provider__c from Case where Id=:srv.CaseId__c ];
            Opportunity opp = [select Id, AccountId  from Opportunity where Id=:srv.OppId__c ];
            srv.Case__c = cs.Id;
            srv.Contact__c = cs.ContactId;
            srv.Account__c = cs.AccountId;
            srv.Service_Provider__c = cs.Service_Provider__c;
            srv.Opportunity__c = opp.Id;
            update srv;
        }
    }
    /*for(Survey__c svr:Trigger.new){
        svr.Case__c = svr.CaseId__c;
       
    }*/

}
  • August 21, 2014
  • Like
  • 0
Hey guys ,

I trying to produce a pdf based on info from a object call document , i have a field call signature_c and if the use field is filed that text will appear in the documento , if not the info will be based on a custom seeting.

My doubt is about the custom setting in the pdf , the custom seeting is called assinatura and will only have one field.

How do i call the custom seeting in the controller and compare with the field in the custom object dociment.

Thank in advance
The Contact Role object can not have fields added to it.  In order to get around this I have created a custom object  with an Object Name= OpportunityContactRoles and gave it a child relationship to the opportunity object.  The custom object has the two fields that are on the Contact Role object, ContactID and Object Name Parts (same as Role), but also has additional fields on it.

What I would like to have happen is every time a Contact name and Parts has been entered into the custom object and saved, a new  standard Contact Role is automatically created on the opportunity with the same Contact name and Role (Parts).  Can anyone help me with a trigger and class for this?  So far I have this but I know it's not even close.


trigger new_Contact_Role_to_Standard on Contact Role
{
   for(Contact Role c : Trigger.New)
   {
        OpportunityContactRole o = new OpportunityContactRole;
        o.ContactId = set the contact id here;
        o.OpportunityId = set the Opportunity id here;
        insert o;
   }
}
Hi! I would like to present my users with a custom VF page for entering/editing records. The page will have a number of tables and the cells of these tables will have a mix of hardcoded values and input options. I thought I was on the right track, but when I try to put an apex:inputField in one of the <td> tags, the HTML breaks and my table gets all messed up.

VF code:
<table border="1" style="width:800px">
                        <tbody><tr>
                            <th>EXCLUDE DBL AND BENEFITS</th>
                            <th>SAMPLE</th>
                            <th>YOURS</th> 
                            <th>KEY</th>
                        </tr>
                        <tr>
                            <td>Gross Commission Pr1</td>
                            <td>300000</td>
                            <td></td><td class="dataCol  first " colspan="2"><input id="j_id0:j_id2:j_id3:section1:j_id13" name="j_id0:j_id2:j_id3:section1:j_id13" size="20" style="width:100px" type="text"></td></tr><tr><td class="dataCol  last " colspan="2"></td>
                            <td>Book of Business minus DBL and Benefits</td>
                        </tr>
                    </tbody></table>
Image of broken table:
User-added image

Hey all

I hope all is well, i really need some help wit the following below.


I have created the following button ( which sits on the campaign object)

User-added image
However when i click on the button i get the following error message

User-added image

This is the class, which i want the button to call. Anyone have any ideas why this is not working ? 

i would like to point out i dont have a test class, and the code coverage is at 0%

This is the apex class which is called from the button 

public String mysw {get; set;}

  Webservice static String initiateswapproval(String mysw) {
    //change Campaign__c to your sObject
   Campaign sw = new Campaign(Id=mysw);

//make sure you add the custom field Submitted for Approval on your object as this is what you
//will use as your approval process entry criteria.
//This is the approval process entry I used: Entry Criteria  (Campaign: Approved Date EQUALS null) AND (campaign: Submitted for Approval EQUALS TODAY)

sw.Submitted_for_Approval__c = System.Now();

update sw;


 // Create an approval request for the record

    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();

    req1.setComments('Submitting request for approval automatically');

    req1.setObjectId(mysw);

    Approval.ProcessResult result = Approval.process(req1);

  return null;


  }
}
This is my approval process. I know that the entry criteria is correct, however i am not sure about the approval steps

User-added image

I am not experienced in Apex Code, but I need a Radar Chart as a dashboard component.  Is there anything on the appexchange, or sample code to get started?
Hi all
I have a problem with SUM (aggregate function).

I summed currency Field(16, 2).
I expected 2 decimal spaces, but The result was just Long.
It's been occuring every currency field in Developer Console, Apex Code, Salesforce.schema
How Can I fix it ?

1. Field : M1_AR__c (Currency 16,2)
2. Query & Apex Code
   AggregateResult[] ar = Database.query(' SELECT Sum(M1_AR__c) , Sum(M1_Fixed__c) '+
                                                                            ' FROM KR_Invoice_New__c WHERE Batch_Month__c = \'2014-05\' '+
                                                                            ' AND M1_Arrear__c > 180 AND M1_Arrear__c < 361 '+
                                                                            ' AND Business_Closure__c <> \'closed business & Collection agency\' ');
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + ar[0].get('expr0'));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + String.valueOf(ar[0].get('expr0')));
   System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ' + Decimal.valueOf(String.valueOf(ar[0].get('expr0'))));

3. Return Value
  - Expected Value :      1788272509.32
  - Real Return Value : 1788272509

4. Each Currency Value
  - Each Currency Value is stored with decimal space 2
  - They was summed => 1788272509.32
User-added image
I am really new at apex code and worse at trying to do the test coverage. My code is only at 65% and I'm at a loss at what else do to. Can anyone help please.

Here is my current test code and my trigger is below that.
The Test Code: Coverage only at 65%
@IsTest Private class TestSRProducts {
   
    testMethod private static void getthedata() {
        // Create the user
       // User testUser = NewObjFactory.buildTestUser(0, 'Pipo', 'Tanya');
       // insert testuser;
        String PM7 = 'Tanya Pipo';
        User testuser = [Select ID, Name
                     From User
                     Where Name = :PM7];
        system.debug('User ' +testuser.id);
      
      
   
        // Create the Account
        Account testacct = NewObjFactory.buildTestAcct(0, 'User - IT', testuser.id);
        insert testacct;
       
       
        // Create the Contact
        Contact testcontact = NewObjFactory.buildTestContact(0, testacct.id, testuser.id);
        insert testcontact;
      
       
        // Create a product
        Product2 testprod = NewObjFactory.buildTestProducts(0);
        insert testprod;
        Product2 testprod2 = NewObjFactory.buildTestProd2(0);
        insert testprod2;
      
       
        // Create a Stocking Request
        Stocking_Request__c testSR = NewObjFactory.buildTestStockingReq(0, testacct.id, testuser.id, testcontact.id);
        insert testSr;
        system.debug('SR ' +testsr.id);
       
        // Create a SR Product and envokes the trigger
        SR_Products__C testsrprod = NewObjFactory.buildtestSRProducts(0, testSR.id);
        SR_Products__C testsrprod2 = NewObjFactory.buildtestSRProducts(0, testSR.id);
        testsrprod2.Product__c = [Select ID from Product2 where name = :'CLS2PAP SHEET SECONDS GLOSS'].id;
        Test.startTest();
        insert testsrprod;
        insert testsrprod2;
        Test.stopTest();
       
        Stocking_Request__c SR1 = [Select ID, Name, product_manager_1__c,
                     product_manager_2__c, product_manager_3__c, product_manager_4__c,
                     product_manager_5__c, product_manager_6__c, product_manager_7__c, product_manager_8__c
                     From Stocking_Request__c
                     Where ID = :testsr.id];           
            If (SR1 != null){
       
         system.debug('product manager is '+SR1.name);
         system.debug('product manager7 is '+ SR1.product_manager_7__c);
          }
        System.assertEquals (SR1.product_manager_7__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_6__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_5__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_4__c, testuser.id);
        System.assertNOtEquals (SR1.product_manager_3__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_2__c, testuser.id);
        System.assertNotEquals (SR1.product_manager_1__c, testuser.id);
       
   
    }    //End getthedata
       
       
} //End Class TestSRProducts
The trigger:

trigger SR_Set_Approvers on SR_Products__c (After insert, After Update) {
   
    // This trigger sets all the product managers from the Stocking Request records
    // With the data from the SR - Product Details records
   
    // Loop all product records that have changed
    for (SR_Products__c prod : Trigger.new) {
       
        // system.debug('product name1 = ' + prod.Stocking_Request__c);
        // Get all the product records related to the SR
        SR_Products__c[] allproducts = [SELECT product_manager__c, PM_Type__C,
                                        stocking_request__c
                            FROM SR_Products__c
                            WHERE stocking_request__c = :Prod.stocking_request__c 
                            ];
        String Pm1 = '';
        String Pm2 = '';
        String Pm3 = '';
        String Pm4 = '';
        String Pm5 = '';
        String Pm6 = '';
        String Pm7 = '';
        String Pm8 = '';
            //Set the PM variables with the PM from the SR-Products records       
        for(SR_Products__c p : allproducts) {
       
            If (p.PM_Type__c == 'PM1')
                pm1 = p.product_manager__c;
            If (p.PM_Type__c == 'PM2')
                pm2 = p.product_manager__c;
            If (p.PM_Type__c == 'PM3')
                pm3 = p.product_manager__c;
            If (p.PM_Type__c == 'PM4')
                pm4 = p.product_manager__c;
            If (p.PM_Type__c == 'PM5')
                pm5 = p.product_manager__c;
            If (p.PM_Type__c == 'PM6')
                pm6 = p.product_manager__c;
            If (p.PM_Type__c == 'PM7')
                pm7 = p.product_manager__c;
            If (p.PM_Type__c == 'PM8')
                pm8 = p.product_manager__c;                   
        } //end loop products
       
        // Get the Stocking Request record
        //system.debug('product name = ' + prod.Stocking_Request__c);
        Stocking_Request__c sr = [Select ID, Name,
                               Product_Manager_1__c, Product_Manager_2__c,
                               Product_Manager_3__c, Product_Manager_4__c,
                               Product_Manager_5__c, Product_Manager_6__c,
                               Product_Manager_7__c, Product_Manager_8__c
                     From Stocking_Request__c
                     Where ID = :prod.Stocking_Request__c];
       
        // Reset all PM fields to blank to start out with
        sr.Product_Manager_1__c = null;
        sr.Product_Manager_2__c = null;
        sr.Product_Manager_3__c = null;
        sr.Product_Manager_4__c = null;
        sr.Product_Manager_5__c = null;
        sr.Product_Manager_6__c = null;
        sr.Product_Manager_7__c = null;
        sr.Product_Manager_8__c = null;
        // Get the user record IDs for the PM variable fields
        // And set the PM fields in the stocking request record
     
        If (PM1 != '' ){
            User u1 = [Select ID, Name
                     From User
                     Where Name = :PM1];           
            If (u1 != null)sr.Product_Manager_1__c = u1.ID;
        } //End PM1 if
       
      
        If (PM2 != '' ){
            User u2 = [Select ID, Name
                     From User
                     Where Name = :PM2];
            If (u2 != null)sr.Product_Manager_2__c = u2.id;
        } //End PM2 if       
      
        If (PM3 != '' ){
            User u3 = [Select ID, Name
                     From User
                     Where Name = :PM3];
            If (u3 != null)sr.Product_Manager_3__c = u3.id;
        } //End PM3 if
       
        If (PM4 != ''){
            User u4 = [Select ID, Name
                     From User
                     Where Name = :PM4];
            If (u4 != null)sr.Product_Manager_4__c = u4.id;
        } //End PM4 if       
      
        If (PM5 != '' ){
            User u5 = [Select ID, Name
                     From User
                     Where Name = :PM5];
            If (u5 != null)sr.Product_Manager_5__c = u5.id;
        } //End PM5 if       
       
        If (PM6 != ''){
            User u6 = [Select ID, Name
                     From User
                     Where Name = :PM6];
            If (u6 != null)sr.Product_Manager_6__c = u6.id;
        } //End PM6 if       
 
        If (PM7 != '' ){
            User u7 = [Select ID, Name
                     From User
                     Where Name = :PM7];
           
            If (u7 != null)sr.Product_Manager_7__c = u7.id;
        } //End PM7 if       
           
        If (PM8 != '' ){
            User u8 = [Select ID, Name
                     From User
                     Where Name = :PM8];
            If (u8 != null)sr.Product_Manager_8__c = u8.id;
        } //End PM8 if
              
       Update sr;
      
    }  // End for looping of changed product records
}
I'm trying to write a Roll-up Summary to Count the Value of Records that were created This Week and Last Week.  However, since Roll-up Summary fields do not support Dynamic Date parameters I need to somehow create a Formula Field that returns a "Yes" or "No" value if the record was created Last Week or This Week.

Does anyone have a clever way of creating a Formula Field on an Object that would return the value of Yes or No based on the following:

1 Field
IF(CreatedDate = "This Week", "This", IF(CreatedDate = "Last Week", "Last", "Neither))

Then I can write a Roll-up Summary to Sum Records where Field = This and a second Rollup Summary where Field = Last.

or

2 Fields
Field 1: IF(CreatedDAte = "This Week", "Yes", "No")

Field2: IF(CreatedDAte = "Last Week", "Yes", "No")

Then I can write a Roll-up Summary to Sum Records where Field1 = Yes and a second Rollup Summary where Field2 = Yes.


Thank you.
Hello Team,

We have couple of questions for submitting app in app exchange

1. After submitting the App for getting the security Review, what is next?

2. What are all the steps involved in assigning a license to a customer?

3. When do we upload the marketing material to our app-exchange listing?

4. When a potential customer asks for a trial - should the customer contact us before they install and start using it?

5. Do we need a copy of license for the customer to sign and start using it.

~Nirmal
I apologize in advance if I don't give enough information or the question isnt clear. I'm new to apex and not sure if this needs to be accomplished via a trigger or a class. 

I grabbed what appears to be a pretty well used trigger and class for rolling up fields from a custom object and customized the trigger for my needs. It works, sort of. I think my issue is because I have some formula fields that feed back and forth between the standard "Contact" object and my custom object for maybe 2 round trips. 

The outcome of the issue after the trigger runs is that I have to go into the custom field, open a record but not actually change anything, save the record, and then the outcome is correct. Is there anyway to force an update of all the objects involved either via a trigger or class? So what is more or less a fake update of a record doesn't have to be done.

I can attach any info needed. 

Thanks,

James
Hello All,

I am having an issue when trying to convert leads. We need to be able to enter the email, phone and address on the account record as well as the contact record. The issue is they are standard fields and when the account or contact already exists it does not override the existing information on the records if they are not blank.

I wanted to know if it was possible to make sure that these fields always override the values through the use of apex code without trying to create hidden fields with workflow rules. I need for the standard email, phone and address fields to always enter in the newly converted information to the records even if they already exist and contain data.

If this is possible with Apex Code does anyone have a snippet that shows how to do this with just one field? If so, could you post an answer to this question? Any help would be tremendously appreciated.

Respectfully,
Scott