• pradeep naredla
  • NEWBIE
  • 258 Points
  • Member since 2014

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 88
    Replies
Can anyone tell what is the relationship between all standard slaesforce objects and give me the uml diagram for those objects

Thanks in advance,
Karthick
Hi

May someone please help, I have written a trigger to create a record in a custom object when a status is changed on my assets. The test class I have passes but the percentage coverage is very low.

Trigger:

trigger createBillableSwappedAsset on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>();

// or whatever your custom object name put instead of Vehicle__c

for ( Asset ass : Trigger.new) {

              if (Trigger.oldMap.get(ass.Id).Movement_Status__c != 'Swapped') {
 
 
  // here is where you check if asset that is being inserted meets the criteria
              if (ass.Movement_Status__c == 'Swapped' && ass.Product2Id != null && ass.Show_Device__c != true) { 


           
       //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b =  new Billable_Swapped_Asset__c ();
        
  // now map asset fields to billable swapped asset that is being created with this asset
 
                      b.Company__c = Trigger.oldMap.get(ass.Id).AccountId;
                      b.Product__c = ass.Product2Id;
                      b.Install_Date__c =  ass.InstallDate;
                      b.End_Date__c = ass.UsageEndDate;
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
        system.debug (e);
    }
}

}


Test Class:

@isTest

private class TestCreateBillableSwappedAsset

{

static testMethod void TestCreateBillableSwappedAsset()
{
    Date todaysDate = System.today();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
        //Create  & Insert Test User
  User u = new User(Alias = 'standt', Email='standarduser@sureswipe.com',
                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                  LocaleSidKey='en_US', ProfileId = p.Id,
                  TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@sureswipe.com'); 
        System.runAs(u)
           
        {
          //Create and Insert Account
  Account a = new Account(Name = 'Test Company', Status__c = 'Active', Industry = 'Fashion',Type = 'Customer',
                                        Company_Email_Adress__c = 'test@test.com');
            insert a;
           
   //Create and Insert Asset
   Asset ass = new Asset(
   Name = 'Test Asset',
   Status = 'Installed',
   AccountId = a.Id,
   InstallDate = System.Today(),
   Product2Id = '01t200000024GTq',
   UsageEndDate = System.Today()
   );
   insert ass;

//Update Asset status to swapped
           
ass.status = 'Swapped';
ass.show_device__c = false;
update ass; 
           
//Update Asset status to swapped with show device true      
ass.status = 'Swapped';
ass.show_device__c = true;
update ass;
           
//Update Asset status to swapped with no product         
ass.status = 'Swapped';
ass.show_device__c = false;
ass.Product2Id = null;
update ass; 
           

        }
    }
}

  • June 19, 2014
  • Like
  • 1
HI evryone,
What is campaign influence and association rule????

Hi All,

I am getting following vioaltion in an extension class. Could you please help me in understanding the vioaltion and how to avoid..

Regards
Hi,


what are the impacts of trigers,validation rules,workflows,approvals,relationships to another objects when we change custom object standard page to visualforce page.
Hi all ,

         Can anybody explain what is the difference between opportunity line item and product and what is the juction object here..?
This my code that sends an email with an attachment.The attachment is supposed to be a file in pdf format.
Error is: email is sent properly with an attachment,but the attachment is not in the pdf format
//Method that sends the pdf as attachment to the customer
    public PageReference sendEmailWithAttachment()
    {
        System.debug('**** curr id is'+currentId);
        //Getting the page to be rendered as pdf
        PageReference pdfPage=new PageReference('/apex/PropertyDetailPage?id='+currentId);
        //pdf.getParameters().put('id',);
        body=pdfPage.getContentAsPdf();
        
        //creating the email attachment
        Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
        attach.setContentType('application/pdf'); 
        attach.setFileName('Property Details');
        attach.setBody(body);
        attach.setInline(false);
        
        //code to send the mail to the specified address
        Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
        String []toaddr=new String[]{cemail};
        email.setToAddresses(toaddr);
        email.setSubject('Acme Property Details');
        email.setHtmlBody('Here is the email you requested! Check the attachment!');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        
        return null;
    }

Waiting for reply...
I have a date field and its a fromula field i need a formula to add 11months to one of the other date fields. formula has to be like it has to add 11months and need to display lastday of the month in my formula tried all the cases 

DATE((YEAR(MyCustome_Field__c)+FLOOR(((MONTH(MyCustome_Field__c)+ 11)-1)/12)),MOD((MONTH(MyCustome_Field__c)+ 11)-1,12)+1,DAY( 
(DATE(YEAR(MyCustome_Field__c),MONTH(MyCustome_Field__c),1)-1)))

I have written this formula but it is not working fine for march i dont know why it is acting weird if i give any date except date in march it is working fine but if i give date in march saylike 12-03-16 it has to show 28-02-17 but it is showing #Error for other months it is working fine help me with this.
---------------VfpageCode---------------

<apex:page standardcontroller="contact" extensions="sample123">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!layout}" value="layout" />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
<!------<apex:inputField value="{!Contact.Accountid}"></apex:inputField>----->
<apex:pageblockSectionItem >
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!state}">
<apex:selectOptions value="{!states}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:selectList size="1" value="{!city}" id="a">
<apex:selectOptions value="{!cities}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

---------------ClassCode---------------
public class sample123
{

    public sample123(ApexPages.StandardController controller)
     {

    }

    public String state {get;set;}
    public String city {get;set;}

    public List<SelectOption> getStates()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- None ---'));        
        options.add(new SelectOption('TN','Tamil Nadu'));
        options.add(new SelectOption('KL','Kerala'));
        return options;
    } 
   
    
    public List<SelectOption> getCities()
    {
        List<SelectOption> options = new List<SelectOption>();
        if(state == 'TN')
        {       
            options.add(new SelectOption('CHE','Chennai'));
            options.add(new SelectOption('CBE','Coimbatore'));
        }
        else if(state == 'KL')
        {       
            options.add(new SelectOption('COA','Coachin'));
            options.add(new SelectOption('MVL','Mavelikara'));
        }
        else
        {
            options.add(new SelectOption('None','--- None ---'));
        }      
        return options;
    }
     public  PageReference layout() {
    
         
        PageReference newPage;

        if (city== 'CHE') {
         newPage = Page.chennai;  
        }
    
    if(city== 'CBE') {
         newPage = Page.Coimbatore;  
        }
     
     if(city== 'COA') {
         newPage = Page.Coachin;  
        }
       
       if(city== 'MVL') {
         newPage = Page.Mavelikara;  
        }
        
        return newPage.setRedirect(true);
     
      }     
}
 

i am working on the functionality of email to case now and i am facing a problem like i am replying from the email in salesforce to the customer mail then i cant send the email with my domine url i.e support url and it was taking the users email as default and so after that i dont have any option to save further conversation in my salesforce database
           how can it will be rectified????
Map<Id, list<Opportunity>> ret = new Map<Id,list<Opportunity>>();
       for(Opportunity order : orders)
       {
      //list<Opportunity> POSO= [SELECT Invoice_Reference_Opp__c,AccountId,Amount,Net_cost__c,VAT__c,StageName,Additional_Order_Information__c from opportunity where opportunity.id=:order.id];
   ret.put(order.Id,new list<opportunity>(order.Invoice_Reference_Opp__c, order.AccountId, order.CreatedDate.getTime(), order.Amount, order.Net_cost__c, order.VAT__c, order.StageName, order.Additional_Order_Information__c));
          //ret.put(order.Id,new list<opportunity>(Invoice_Reference_Opp__c,AccountId,Amount,Net_cost__c,VAT__c,StageName,Additional_Order_Information__c from opportunity where opportunity.id=:order.id) );
           //ret.put(order.Id,POSO);
           ret.get(order.Id).Products = new List<POSProductDetailReturn>();
           order.Sent_to_POS__c = true;
          
       }

GETTING ERROR AS

Error: Compile Error: expecting a right parentheses, found ',' at line 19 column 73

my requirment is how to sync contacts in salesforce to other crm's may i know the process or sample examples or links. Everywhere i am getting sync fom other's to salesforce. Can anyone help me with this.
trigger AttachmentandReferralpoints on Student_Profile__c (before insert, after insert,after update) {


if(trigger.isupdate){

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.points__c=50;
Student_Profile__c referedpersonid=[select id from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];
rp.Refered_Person__c =referedpersonid.id;
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}
}

hi guys....!!
I think its becouse of recusrsive trigger, but unable solve..
Please help me to bulkify this trigger or solve the prob..
Hi,
            What is the main differences between before using technologies OR CRMs and salesforce CRM .What is the main goal of of CRM,Features and Why maximum peoples interesting the salesforce CRM.

Difference between customers and Users in salesforce?

EXample:I have one company, In my company salesforce CRM is there ,What is the use of Salesforce CRM ?


please Give me brief description
Hi,

I have written a test method in my test class to test the after update event on Lead trigger. On update of the Lead record child Staff_Information__c record should be updated. The trigger is working fine. But my test method fails giving the following error 'Assertion Failed: Expected: Test FN, Actual: Update - Test First Name AS1'. But actually I am providing here the correct values. Could anyone point out what the mistake is? Here is my code.

@isTest(SeeAllData = true)
public static void Test_ENT_AdvisoryService_Triggers4()
  {
    // Initialise variables. 
    List<Lead> lstLeads = new List<Lead>();
    List<ENT_AS_Staff_Information__c> lstASStaffInformation = new List<ENT_AS_Staff_Information__c>();
    List<Lead> lstASLeadsToUpdate = new List<Lead>();
   
    Test.startTest();
   
    // Insert test Lead records.
    lstLeads = GenerateAdvisoryServicesTestLeads(100);
    System.assertEquals(lstLeads.size(),100);
   
    if(lstLeads != null && lstLeads.size() > 0)
    {
      lstASStaffInformation = GenerateTestASStaffInformationForLeads(lstLeads);
    }
       
    System.assertEquals(lstASStaffInformation.size(),100);
    System.assertEquals(lstASStaffInformation[0].Member_First_Name__c, 'Test FN');
     
    if(lstLeads != null && lstLeads.size() > 0)
    {
        for(Lead leadToUpdate: lstLeads)
        {    
            leadToUpdate.Additional_info_on_services__c = 'Update - Test Additional information on service';
            leadToUpdate.Expertise_of_key_personal__c = 'Update - Test Key Personal skills';
            leadToUpdate.Is_your_organization_registered_with_SAM__c  = 'No';
            leadToUpdate.Languages_conversationally__c = 'Update - English, Update - French';
            leadToUpdate.Languages_High_proficiency__c = 'Update - English';
            leadToUpdate.FirstName = 'Update - Test First Name AS1';
            leadToUpdate.LastName = 'Update - Test Last Name AS1';
            leadToUpdate.Job_Title__c = 'Update - Asset Manager';
            leadToUpdate.Experience_with_cities__c = 'Update - Columbia, Update - New York';
            leadToUpdate.Experience_with_coordination__c = 'Update - Test Description';
            leadToUpdate.Place_availability__c = 'Update - Columbia';
            leadToUpdate.Rate_support__c = 'Update - 60 USD for 1 day';
            leadToUpdate.References_name__c = 'Update - Test Reference';
            leadToUpdate.SAM_Expiration_Date__c = Date.today();              
            leadToUpdate.Company = 'Update - Test Company';
            leadToUpdate.Title = 'Test Title';
            leadToUpdate.Email = 'test@gmail.com';
            leadToUpdate.References_organization__c = 'Test Ref Org';
            leadToUpdate.References_email__c = 'testref@gmail.com';
            leadToUpdate.References_phone__c = '(401)-402-4433';
            leadToUpdate.References_title__c = 'Test Ref Title';
            leadToUpdate.Website = 'testweb.com';
            leadToUpdate.Contact_phone_number__c = '(456)-456-4567';
            leadToUpdate.Contact_Fax_Number__c = '(477)-477-7744';
            leadToUpdate.DUNS_Number__c = '12345';
            leadToUpdate.Federal_EIN__c  = '12345';
            leadToUpdate.Street = 'Test Street';
            leadToUpdate.City = 'Test City';
            leadToUpdate.State = 'NY';
            leadToUpdate.PostalCode = '54321-4321';
            leadToUpdate.Country = 'US';           
            lstASLeadsToUpdate.add(leadToUpdate); 
         } 
    } 
       
    // Check that list of updated Lead records is not empty and if not update the list.
    if(lstASLeadsToUpdate.size() > 0)
    {
        UPDATE lstASLeadsToUpdate;
    }
    System.assertEquals(lstASLeadsToUpdate.size(),100);
       
    // Update the related Staff Information record.
    if(lstASStaffInformation.size() > 0)
    {
        UPDATE lstASStaffInformation;
    }
    System.assertEquals(lstASStaffInformation.size(),100);
    // Check whether Staff Information records for Advisary Service Leads are updated.
    if(lstASStaffInformation.size()>0)
    {
        System.assertEquals(lstASStaffInformation[0].Member_first_name__c, 'Update - Test First Name AS1');
        System.assertEquals(lstASStaffInformation[0].Member_last_name__c, 'Update - Test Last Name AS1');
        System.assertEquals(lstASStaffInformation[0].Member_Title__c , 'Test Title');
        System.assertEquals(lstASStaffInformation[0].Rate_support__c, 'Update - 60 USD for 1 day');
        System.assertEquals(lstASStaffInformation[0].Selec_if_the_organization_is_registered__c,'No');
        System.assertEquals(lstASStaffInformation[0].Place_availability__c ,'Update - Columbia');
        System.assertEquals(lstASStaffInformation[0].Additional_info_on_services__c, 'Update - Test Additional information on service');
        System.assertEquals(lstASStaffInformation[0].Languages_high_profeciency__c,'Update - English' );
        System.assertEquals(lstASStaffInformation[0].Languages_conversationally__c,'Update - English, Update - French');
        System.assertEquals(lstASStaffInformation[0].Email__c,'test@gmail.com');
        System.assertEquals(lstASStaffInformation[0].Expertise_of_key_personnel__c,'Update - Test Key Personal skills');
        System.assertEquals(lstASStaffInformation[0].Narrative_Expertise_of_key_personal__c , 'Update - Test Key Personal skills');
        System.assertEquals(lstASStaffInformation[0].Narrative_Experience_with_cities__c, 'Update - Columbia, Update - New York');
        System.assertEquals(lstASStaffInformation[0].Narrative_Experience_with_coordination__c,'Update - Test Description');
        System.assertEquals(lstASStaffInformation[0].Reference_organization__c, 'Test Ref Org');
        System.assertEquals(lstASStaffInformation[0].Reference_email__c, 'testref@gmail.com');
        System.assertEquals(lstASStaffInformation[0].Reference_name__c,'Update - Test Reference');
        System.assertEquals(lstASStaffInformation[0].Reference_phone__c,'(401)-402-4433' );
        System.assertEquals(lstASStaffInformation[0].Reference_title__c,'Test Ref Title' );
        System.assertEquals(lstASStaffInformation[0].SAM_Expiration_Date__c,Date.today()) ;
        System.assertEquals(lstASStaffInformation[0].Website__c, 'testweb.com');
        System.assertEquals(lstASStaffInformation[0].Contact_phone_number__c,'(456)-456-4567');
        System.assertEquals(lstASStaffInformation[0].Contact_Fax_Number__c, '(477)-477-7744');
        System.assertEquals(lstASStaffInformation[0].DUNS_Number__c,'12345');
        System.assertEquals(lstASStaffInformation[0].Federal_EIN__c, '12345');
        System.assertEquals(lstASStaffInformation[0].Address__c ,String.valueOf('Test Street'+'Test City'+'NY'+'54321-4321'+'US'));
    }
        Test.stopTest();
  }
Can anyone tell what is the relationship between all standard slaesforce objects and give me the uml diagram for those objects

Thanks in advance,
Karthick
TRigger
---------------------------------
trigger OpportunityTrigger on Opportunity (After insert,After update)
{
    if(trigger.isAfter )
   
    {
        if(trigger.isInsert){
            List<OpportunityContactRole> lstContactRoletoUpdate = new List<OpportunityContactRole>();
            Set<String> setOppId = new Set<String>();
                    system.debug('!!!!After insert');
                    List<OpportunityContactRole> lstOppContactRolePrimary = new List<opportunityContactRole>();
                    for(Opportunity o:trigger.new)
                    {
                        setOppId.add(String.valueOf(o.id));
                        system.debug('@@@@@setOppId '+(String.valueOf(o.id)) );
                    }
           
                    lstOppContactRolePrimary = [select id,contactId,opportunityId from OpportunityContactRole where opportunityId in :setOppId];
                    //no primaryContact role found at all have make from scratch
                    system.debug('lstOppContactRolePrimary '+lstOppContactRolePrimary );
                    if(lstOppContactRolePrimary.size() > 0)
                    {
                        Map<String,OpportunityContactRole> mapOppIdConrole = new Map<String,OpportunityContactRole>();
                        for(OpportunityContactRole conRole:lstOppContactRolePrimary)
                        {
                            mapOppIdConrole.put(String.valueOf(conRole.opportunityId),conRole);
                        }
                        for(String id:setOppId)
                        {
                            if(mapOppIdConrole.containsKey(id))
                            {
                                Opportunity oppTeamp = trigger.newMap.get(id);
                                if(oppTeamp.buyer__c == mapOppIdConrole.get(id).contactId)
                                {
                                    //both are equal , we will just have to update the role
                                    OpportunityContactRole tempRole = mapOppIdConrole.get(id);
                                    tempRole.Role = 'Buyer';
                                    lstContactRoletoUpdate.add(tempRole);
                                }
                                else
                                {
                                    //we have the contact role but the contacts are different
                                    OpportunityContactRole tempRole = mapOppIdConrole.get(id);
                                    tempRole.Role = 'Buyer';
                                    tempRole.contactId = oppTeamp.buyer__c;
                                    lstContactRoletoUpdate.add(tempRole);
                                }
                            }else
                            {
                                // we have to make contact role
                                System.debug('####Creating absolutely new one 1');
                                OpportunityContactRole tempRole = new OpportunityContactRole();
                                tempRole.Role = 'Buyer';
                                tempRole.contactId = trigger.newMap.get(id).buyer__c;
                                tempRole.isPrimary = true;
                                lstContactRoletoUpdate.add(tempRole);
                            }
                        }
                    }else
                    {
                        System.debug('####Creating absolutely new one 2');
                        opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
                        objopportunityTriggerHandler.createNewContact(trigger.new);
                    }
                if(lstContactRoletoUpdate.size() > 0)
                {
                    upsert lstContactRoletoUpdate;
                }  
           
        }
    }
    /*
    if(trigger.isBefore)
    {
        if(trigger.isInsert)
        {
                    system.debug('!!!!Before Insert');
                    for(Opportunity o:trigger.new)
                {
                    List<OpportunityContactRole> lstOppContactRolePrimary = [select id,contactId from OpportunityContactRole where opportunityId =: o.id];
                    System.debug('!!!!Before insert contact id'+o);
                    System.debug('!!!!Before insert buyer id'+o.buyer__c);
                    System.debug('!!!!Before lstOppContactRolePrimary = >'+lstOppContactRolePrimary);
                }
           
        }
    }
    */ 
        //opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
        //objopportunityTriggerHandler.createNewContact(trigger.new);
   
   
    //code added by deepak dhingra on 13/6/2014 to update the line items
     if(trigger.isAfter && trigger.isUpdate)
     {
        Set<string> qualifiedOppId = new Set<string>();
        for(Opportunity o:Trigger.new)
        {
            if(o.Agency_Discount_Percentage__c != Trigger.Oldmap.get(o.id).Agency_Discount_Percentage__c)
            {
                qualifiedOppId.add(String.valueOf(o.id).left(15));
            }
           
        }
       
        if(qualifiedOppId.size() > 0)
        {
            List<OpportunityLineItem> lstLineItems = new List<OpportunityLineItem>();
            lstLineItems  = [select id from OpportunityLineItem where opportunityid in :qualifiedOppId];
            if(lstLineItems.size() > 0)
            {
                update lstLineItems;
            }
        }


_______________________________

TRACKER CLASSSSSSS



@isTest
public class OpportunityTriggerHandlerTest
{
static testMethod void insertOpportunity()
{
Account objAccount = new Account();
objAccount.Name = 'Vivek';
objAccount.Type = 'Supplier';
objAccount.Phone = '1234';
objAccount.CurrencyIsoCode = 'AUD';
insert objAccount;

Contact objcontact = new contact();
objcontact.LastName = 'Singh';
objcontact.CurrencyIsoCode = 'AUD';
objcontact.Accountid = objAccount.id ;
insert objContact;

opportunity objopportunity= new opportunity ();
objopportunity.Name = 'Hindi2014';
objopportunity.CloseDate = System.Today();
objopportunity.Accountid = objAccount.id;
objopportunity.Buyer__c = objcontact.id;
objopportunity.Vendor__c = objaccount.id;
objopportunity.StageName = 'Prposal Sent';
objopportunity.Billing_Terms__c = 'On Completion';              
objopportunity.Type = 'New Business';
insert Objopportunity;

OpportunityContactRole objOpportunityContactRole=new OpportunityContactRole();
   objOpportunityContactRole.ContactId = Objopportunity.Buyer__c;
   objOpportunityContactRole.OpportunityId = Objopportunity.Id;
   objOpportunityContactRole.Role = 'Buyer';
  insert objOpportunityContactRole;

  List<OpportunityContactRole> lstOpportunityContactRole = new List<OpportunityContactRole>();
           //OpportunityContactRole = [select id from OpportunityContactRole where OpportunityContactRole ='Buyer'];

}
static testMethod void updateOpp()
{
  opportunity objopportunity2= new opportunity ();
  objopportunity2.Name = 'Hindi2015';
  //upadte Objopportunity2;
}
}
Hi,

How do goo about writing Test Class for this piece of Trigger?

trigger updateopps on Quote(after insert, after update)
{             
     Map<Id,Opportunity> miMap = new Map<Id,Opportunity>();
     Set<id> Ids = new Set<id>();
         for (Quote  mir : Trigger.new)
         {
             Ids.add(mir.OpportunityId);
         }
    
     Map<id,Opportunity> miMap2 = new Map<id,Opportunity>([Select Id, Project_Engineer_1__c,Project_Engineer_2__c from Opportunity Where Id in :Ids]); 

         for (Quote mir : Trigger.new)
         {
         if(mir.Primary__c){
             Opportunity mi = miMap2.get(mir.OpportunityId);
             mi.Project_Engineer_1__c = mir.Project_Engineer_1__c;
             mi.Project_Engineer_2__c = mir.Project_Engineer_2__c;
             miMap.put(mi.id,mi);
         }}
        
         if(!miMap.isEmpty())
         {
             update miMap.values();
         }
}
  • June 20, 2014
  • Like
  • 0
Hi All

How to write a trigger on chatter post that alerts Users a comment has been made.

Thanks
Hi all,
I am trying to write a trigger that would obtain unique set of values from a child object and update the parent object Multi-Select Picklist field.
Now the issue is that when I edit the same record in the child twice and the status is equal to Active it comes up in the Multi-Select twice when it should be there once.
For example,
Market Type Child field = RV,Truck,Car
On the account the Market Type is the same until I edit the child record again let say RV
on the Account it will then show RV;RV;Truck;Car...
Here is my code:
trigger PopulateMarketType on Account_Market__c (after insert,after update) {
/*************************Variable Section*************************************/
    List<ID> AccIDs = new List<ID>();
    
    List<Account> updateAccList = new List<Account>();
    
    Map<ID,Account> AccUpdateMap = new Map<ID,Account>();
    
    Set<String> subAccNames = new Set<String>();
    
    List<Account> clearvaluesMT = new List<Account>();
    
    String[] UniqueMTs;
    
    String FinalUnique;
    Integer x=0;
 /****************************************************************************/
 
/**********************Retrieve Account Id's from the new AMI records***************/    
    For( Account_Market__c ami: Trigger.New)
    {
            AccIDs.add(ami.Account__c);
    }
     
    For(Account acc : [Select ID, Market_Type__c from Account where ID in:AccIDs])
    {
             AccUpdateMap.put(acc.ID ,acc );
    }

    
    /****I like to clear out all the values in the Market Type Field in the Account and then re-insert them in****/
   /*For (Account clearthis : [Select Market_Type__c from Account where ID in:AccIDs])
    {
            System.Debug('zzz32'+clearthis.Market_Type__c);
            clearthis.Market_Type__c = '';   
                    
            clearvaluesMT.add(clearthis);
            System.Debug('zzz35'+clearthis.Market_Type__c);
             update clearvaluesMT;  
    }    
    If (clearvaluesMT != null && clearvaluesMT.size() > 0) 
    {             
        update clearvaluesMT;   
        System.Debug('zzz38'+clearvaluesMT);
    }*/
 /**********************************************************************************************************/   
    /**Re-Insert the Market Types in for the associated Account*****/ 
    For (Account_Market__c amii: Trigger.New)
    {
    
             Account updateacc = AccUpdateMap.get(amii.Account__c);
                If (amii.Status__c == 'Active') 
                 {
                     
                     If (updateacc.Market_Type__c ==null)
                     {                        
                         updateacc.Market_Type__c = amii.Market_Type__c;   
                      }
                      else
                      {
                      
                      //1st - get all the values
                          updateacc.Market_Type__c += +';'+ amii.Market_Type__c; 
                           
                     //2nd - place them in a set to  become unique     
                          subAccNames.add(updateacc.Market_Type__c );
                     
                     //3rd - put them in a string   
                          FinalUnique = String.valueof(subAccNames);
                          System.Debug('zzz74'+FinalUnique);
                      
                      //4th - take away the {} from value
                            if(FinalUnique.contains('{'))
                            {
                                FinalUnique = FinalUnique.replace('{', ' ');
                            }
                            
                            if(FinalUnique.contains('}'))
                            {
                                FinalUnique = FinalUnique.replace('}', ' ');                                  
                            }                         
                     
                     //5th - Finally update the Market type with the Final Value     
                         updateacc.Market_Type__c  = FinalUnique;      
                 
                     }               
                 updateAccList.add(updateacc);    
                 } 
                   
    }
    If (updateAccList != null && updateAccList.size() > 0)
        
            update updateAccList;

}

Thank you
Hi

May someone please help, I have written a trigger to create a record in a custom object when a status is changed on my assets. The test class I have passes but the percentage coverage is very low.

Trigger:

trigger createBillableSwappedAsset on Asset (after update) {

List <Billable_Swapped_Asset__c> auditTrailList = new List <Billable_Swapped_Asset__c>();

// or whatever your custom object name put instead of Vehicle__c

for ( Asset ass : Trigger.new) {

              if (Trigger.oldMap.get(ass.Id).Movement_Status__c != 'Swapped') {
 
 
  // here is where you check if asset that is being inserted meets the criteria
              if (ass.Movement_Status__c == 'Swapped' && ass.Product2Id != null && ass.Show_Device__c != true) { 


           
       //instantiate the object to put values for future record 
  Billable_Swapped_Asset__c  b =  new Billable_Swapped_Asset__c ();
        
  // now map asset fields to billable swapped asset that is being created with this asset
 
                      b.Company__c = Trigger.oldMap.get(ass.Id).AccountId;
                      b.Product__c = ass.Product2Id;
                      b.Install_Date__c =  ass.InstallDate;
                      b.End_Date__c = ass.UsageEndDate;
 
  auditTrailList.add(b);
 
 
  }//end if
 
}//end for ass

//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
  insert auditTrailList;
} catch (system.Dmlexception e) {
        system.debug (e);
    }
}

}


Test Class:

@isTest

private class TestCreateBillableSwappedAsset

{

static testMethod void TestCreateBillableSwappedAsset()
{
    Date todaysDate = System.today();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
        //Create  & Insert Test User
  User u = new User(Alias = 'standt', Email='standarduser@sureswipe.com',
                  EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
                  LocaleSidKey='en_US', ProfileId = p.Id,
                  TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@sureswipe.com'); 
        System.runAs(u)
           
        {
          //Create and Insert Account
  Account a = new Account(Name = 'Test Company', Status__c = 'Active', Industry = 'Fashion',Type = 'Customer',
                                        Company_Email_Adress__c = 'test@test.com');
            insert a;
           
   //Create and Insert Asset
   Asset ass = new Asset(
   Name = 'Test Asset',
   Status = 'Installed',
   AccountId = a.Id,
   InstallDate = System.Today(),
   Product2Id = '01t200000024GTq',
   UsageEndDate = System.Today()
   );
   insert ass;

//Update Asset status to swapped
           
ass.status = 'Swapped';
ass.show_device__c = false;
update ass; 
           
//Update Asset status to swapped with show device true      
ass.status = 'Swapped';
ass.show_device__c = true;
update ass;
           
//Update Asset status to swapped with no product         
ass.status = 'Swapped';
ass.show_device__c = false;
ass.Product2Id = null;
update ass; 
           

        }
    }
}

  • June 19, 2014
  • Like
  • 1
HI evryone,
What is campaign influence and association rule????

I have the below code.

public class mycontroller
{
           public ApexPages.StandardSetController con{       
        get {
            Id accId = system.currentPageReference().getParameters().get('Id');
            str = String.valueOf(accId).left(3);
            if(accId!=null && str == '001')
           {
                if(con!=null)
                {
                             con = new ApexPages.StandardSetController(Database.getQueryLocator([select id from relationship__c where acccount__c =: Accid]));

                }
                        ---
                        ---
                        ---
           }
          return con;
          }
        set;
      }

}

I have tried with the below code but not entering into getter of the "public ApexPages.StandardSetController con" 

@isTest(seeAllData=True)
private class ViewConnectioncontrollerTest1
{
    static testMethod void  ViewConnectioncontrollerTestMethod()
    {       

        List<Account> acc = new List<Account>();
        acc = [select Id,Name from Account limit 1];                    
       
         ApexPages.currentPage().getParameters().put('accid', acc[0].id);
         System.debug('********* acc id ********' +acc[0].id);
         ApexPages.StandardSetController ssc = new ApexPages.Standardsetcontroller(acc);       
         ViewConnectioncontroller vcc = new ViewConnectioncontroller();
         vcc.con = ssc;
         // vcc.con.accid = acc[0].id;        
       
    }
}

pls help
Hi everyone,

I am new to salesforce and I wanted to know if it was possible to add a button in the "new Account" standard page.
Here is a screenshot of what I mean :

User-added image

Thanks in advance for your answers.

Have a good day.
Hello,

I am planning to write a trigger on Event Object.
The trigger will fire when the Event Expires.
Can this be possible?

Thanks,
Mayank