+ Start a Discussion
amit kalwaramit kalwar 
hi all,
     i want to create a visualforce page using Action Function in which we have two drop down lists( Country and State). when i select a country from drop down it should automatically shows the states of that country in other dropdown list automatically without reloading a page .(like AJAX).
any suggestion?
Regards
Amit
Best Answer chosen by amit kalwar
Sohan Raj GuptaSohan Raj Gupta
Hi Amit,

You can achieve your requirement using following process:
1) Custom Setting
2) Action Function

 1) Custom Setting: Please refer this https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm

2) Action Function: Ajay give you best example for this, but in Apex Function you have to create Global picklist OR country and state picklist for each obejct with all country and state values. If you will create custom setting then no need to create country and state picklist for each object with all values.

Custom setting is best way to achieve country and state values.

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 

 
Cosimo FaggianoCosimo Faggiano 
Hi all,

i don't have the contacts menu on my home page. 

User-added image
how can I activate the feature?

thanks
 
Best Answer chosen by Cosimo Faggiano
SandhyaSandhya (Salesforce Developers) 
Hi,

Click on App launcher and select Sales to see the contacts tab.

User-added image


User-added image

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper soultion.

Best Regards,
​Sandhya
 
 
Nathan Prats 22Nathan Prats 22 
Hi, 

I'm trying to update a field named Primary Partner Gross Margin on the opportunity object based on opportunity line items. 
The code compiles, but it doesn't update the field on update. Any idea why ? 
trigger OpportunityTriggers on Opportunity (before update) {
    
    // Quand 1 Opp a un Primary Partner Account Reseller, remplir le champs "Primary Partner Gross Margin" = Sum OpportunityLineItems Software  * Primary_Partner_Margin__c
    // C'est forcément before car on a besoin d'update des records, et quand on est en after, les records sont lock
    
    // Prendre la liste des opportunités pour lesquelles on va peupler Primary_Partner_Gross_Margin__c
    For (Opportunity opp : [SELECT Id,Primary_Partner_Gross_Margin__c,Primary_Partner_Margin__c 
                            FROM Opportunity
                            WHERE Primary_Partner_Role__c ='Reseller'
                            AND Deal_with_a_partner__c = 'Yes'
                            AND Id IN :Trigger.old
                           ]) {
                               
                               // Updater le champs Primary_Partner_Gross_Margin__c
                               Double GrossMargin = [SELECT TotalPrice 
                                                      FROM OpportunityLineItem
                                                      WHERE PricebookEntry.product2.Family='Software'
                                                      AND  OpportunityId =: opp.Id ][0].TotalPrice;
                               
                               
                               opp.Primary_Partner_Gross_Margin__c=GrossMargin*opp.Primary_Partner_Margin__c;
                               opp.Name = 'Worked';
                               
                           }
}

 
Best Answer chosen by Nathan Prats 22
balaji Jayararmanbalaji Jayararman
Hi Nathan,

Please write a trigger on opportunity line items. Here's the code you are looking for
trigger OpportunityTriggers on OpportunityLineItem (after insert, after update) {

	// Quand 1 Opp a un Primary Partner Account Reseller, remplir le champs "Primary Partner Gross Margin" = Sum OpportunityLineItems Software  * Primary_Partner_Margin__c
	// C'est forcément before car on a besoin d'update des records, et quand on est en after, les records sont lock

	// Prendre la liste des opportunités pour lesquelles on va peupler Primary_Partner_Gross_Margin__c
	Set<Id> oppIdSet = new Set<Id>();
	for (OpportunityLineItem oppLineItem : Trigger.new) {
		if (opp.OpportunityId != null) {
			oppIdSet.add(opp.OpportunityId);
		}
	}
	if (oppIdSet.isEmpty()) {
		return;
	}
	Map<Id, Opportunity> oppUpdateMap = new Map<Id, Opportunity>();
	for (Opportunity opp : [
		SELECT
			Primary_Partner_Margin__c,
			(SELECT
				TotalPrice 
			FROM
				OpportunityLineItems
			WHERE
				PricebookEntry.product2.Family = 'Software')
		FROM
			Opportunity
		WHERE
			Id IN :oppIdSet AND
			Primary_Partner_Role__c = 'Reseller' AND
			Deal_with_a_partner__c = 'Yes'
	]) {
		Double grossMargin = 0;
		for (OpportunityLineItems oppLineItems : opp.OpportunityLineItems) {
			grossMargin += oppLineItems.TotalPrice;
		}
		opp.Primary_Partner_Gross_Margin__c = grossMargin * opp.Primary_Partner_Margin__c;
		opp.Name = 'Worked';
		oppUpdateMap.put(opp.Id, opp);
	}
	if (!oppUpdateMap.isEmpty()) {
		update oppUpdateMap.values();
	}
}

Hope it solves your problem.

Please mark this as best answer if it solves.

Thanks,
Balaji J 
Varun TejaVarun Teja 
Can you please help on below criteria.

1) A picklist showing values 2011, 2012 and 2013
2) 2 Date fields (From Date and To Date)
3) When user picks the value in 1st picklist, From and To Date should automatically populate.
Ex: If I select 2011, From Date should be 01/01/2011 and End ddate should be 12/31/2011 automatically populate
If I select 2012, From Date should be 01/01/2012 and End ddate should be 12/31/2012 automatically populate

I have picklist as Year__c

Below formula has been given in From Date filed.

CASE(Year__c, 
2011 , DATE(2011,01,01) , 
2012, DATE(2012,01,01),
DATE(2013,01,01)


Getting error as "Error: Field Year__c may not be used in this type of formula"

Thanks In Advance
Best Answer chosen by Varun Teja
Somya SrivastavaSomya Srivastava
Hi Varun,

Use this:

CASE(Year__c, 
'2011' , DATE(2011,01,01) , 
'2012', DATE(2012,01,01),
DATE(2013,01,01)


Thanks
Somya


 
Diwakar GDiwakar G 
Hi,

In Setup->Users->Fields->Lanuage only field information is available. How to see the picklist values?
Thanks in advance.
Best Answer chosen by Diwakar G
Sohan Raj GuptaSohan Raj Gupta
Hi Diwakar,

You can manage Language filed values from "Language Settings".

Go to Steup->Language Settings



Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
Akash Choudhary 17Akash Choudhary 17 
Hi All, 

I need to bulkify this code please help.

public class Move_Contact {
    public static void updateContact(List <Contact> conList){
        Map <Id,Id> conMap = new Map <Id,Id>();
        
        for(Contact myCon : conList){
            if(myCon.Email != null){
                string domain = myCon.Email.split('@').get(1);
               
                String MainDomain = domain;
                string website ='www.' +MainDomain;
                string httpWebsite ='http://www.' + MainDomain;
                string httpswebsite ='https://www.'+ MainDomain;
                string international = MainDomain + '.%';
                
                Account acc = [SELECT Id
                               FROM Account 
                               WHERE Website =:website
                               or Website =:httpWebsite
                               or Website =:httpswebsite
                               or Website =:international Limit 1];
                
                myCon.AccountId = acc.Id ;
            }
        }
        
       
    }
    
}
Thanks
Best Answer chosen by Akash Choudhary 17
Steven NsubugaSteven Nsubuga
public class Move_Contact {
    public static void updateContact(List <Contact> conList){
        
		Set <String> contactIds = new Set <String>();
        Set <String> sites = new Set <String>();
        for(Contact myCon : conList){
			contactIds.add(myCon.Id);
            if(myCon.Email != null){
                string domain = myCon.Email.split('@').get(1);
               
                String MainDomain = domain;
                string website ='www.' +MainDomain;
                string httpWebsite ='http://www.' + MainDomain;
                string httpswebsite ='https://www.'+ MainDomain;
                string international = MainDomain + '.%';
                sites.add(website);
				sites.add(httpWebsite);
				sites.add(httpswebsite);
				sites.add(international);
            }
        }
		
		List<Account> accs = [SELECT Id, Website FROM Account WHERE Website IN:sites];
		Map <String, Id> websiteIdMap = new Map <String, Id>();
		for(Account acc : accs){
			websiteIdMap.put(acc.Website, acc.Id);
		}
		
		List<Contact> contactList = [SELECT Id, Email, AccountId FROM Contact WHERE Id IN:contactIds];
		for(Contact myCon : contactList){
            if(myCon.Email != null){
                string domain = myCon.Email.split('@').get(1);
                
				for(String website : websiteIdMap.keyset()) {
					if (website.contains(domain)) {
						myCon.AccountId = websiteIdMap.get(website);
						break;
					}
				} 
            }
        }
		update contactList;
    }
}

 
anil maligaanil maliga 
trigger anyname on paytm__c (before insert,after update) {
for(paytm__c y:trigger.new){
if(y.phn_no__c<=10){
y.phn_no__c.adderror('hello enter vaild phone number');
}
}
}
Best Answer chosen by anil maliga
Raj VRaj V
Looks like the phone number is of type String so change the code as below 
 
trigger anyname on paytm__c (before insert,after update) {
for(paytm__c y:trigger.new){
if(y.phn_no__c.length()<=10){
y.phn_no__c.adderror('hello enter vaild phone number');
}
}
}



 
srikanth kambampati 6srikanth kambampati 6 
Hi, i wrote one trigger on account object, when even an account is created automatically create a contact for that account. And my trigger is 
trigger acc_con on Account (after insert) {
    List<Contact> cons = new List<Contact>();
    for(Account a:trigger.new) {
        Contact c =new Contact();
        c.lastName = a.Name;
        c.Phone = a.phone;
        c.AccountId = a.id;
        cons.add(c);
    }
    insert cons;
}
Best Answer chosen by srikanth kambampati 6
Raj VRaj V
Updated  --- 100 % code coverage 
 
@isTest
private class TestAccountTrigger {
    static testmethod void testEx2(){
        Test.startTest();
        Account a = new Account();
        a.Name = 'test';
        insert a;
        Test.stopTest();
        
    }
}

 
sekhar123sekhar123 
Hi experts..
pls find below my requirement scenario :
i have custom object (test_custObj) and  fileds  are ( age,street city, phone,email and contact_lookup( contact lookup field) ).  i already maintaed lookup relationship between custom object and contact .
Thrid party system sending details based on Contact ......i can able to store all the fields but not contact_lookup field . 
for example :
my third party sending details like   '23',' YG colony',' Hyd','88888888','abc@gmail.com'  and ' AMAR'.
i can able to store all the values expect 'AMAR' ( contact_lookup)
can some one help me how can i save/store  contact_lookup filed in custom object ?  
its urgent one ....thanks 


 
Best Answer chosen by sekhar123
balaji Jayararmanbalaji Jayararman
Hi sekar,
1. if the contact record exist in your system, you have to query the record using filters(Name or email) and then populate the contact record id to the IVR_Journey__c filed.

2. If the contact record does not exist, the create account and contact record using datas received from thirparty system and then populate the contact record id to the IVR_Journey__c filed.
 
global class IVRObjWebservice
{
webservice static Id createIVRRecord(String CallerID, String ContactChannel,String ContactIntent,String AuthenticationResult,
                                         String AutomatedTaskCompleted,String dob,String DNIS,String enddate,
                                         String LanguagePreference,String SeqMemberID,String SSN,String startdate,
                                         String subscriberId,String SubscriberPlanID,String SubscriberType,String SurveyOption,
                                         String TransferedTo,String ccChannelDuration,String ivrjourney)
    {
IVR_Journey__c con = new IVR_Journey__c();
con.Caller_ID__c = Integer.valueOf(CallerID);         
con.Authentication_Result__c = AuthenticationResult;
con.Automated_Task_Completed__c = AutomatedTaskCompleted;
con.Contact_Channel__c = ContactChannel;
con.Contact_Channel_Duration__c = ccChannelDuration;
con.Contact_Intent__c = ContactIntent;
con.DNIS__c = Integer.valueOf(DNIS);        
con.Language_Preference__c = LanguagePreference;
con.Seq_Member_ID__c = Integer.valueOf(SeqMemberID);        
con.SSN__c = Integer.valueOf(SSN);       
con.Start_Date_Time__c = Datetime.valueOf(startdate);        
con.End_Date_Time__c = Datetime.valueOf(enddate);        
con.Date_of_Birth__c = Date.valueOf(dob);
con.Subscriber_ID_Numeric__c = Integer.valueOf(subscriberId);        
con.Subscriber_Plan_ID__c = SubscriberPlanID;
con.Subscriber_Type__c = SubscriberType;
con.Survey_Option__c = SurveyOption;
con.Transfered_To__c = TransferedTo;
Contact cnt;
try {
    //Query if contact exist in the system using filters
     cnt = [SELECT Id from Contact WHERE Name = :'contact_Name_from_thirdparty' 
      OR Email =:'Email from thirpaty' LIMIT 1 ];
} catch(Exception e) {
       //Create Account & contact record using datas received from the third party 
         system,if contact record does not exist.
       Account acc = new Account();   
        acc.name = 'Test Account';
        acc.BillingStreet='Test Street';
        acc.BillingCity='Test City';
        acc.BillingState='TEest';
        acc.BillingCountry='USA';
        acc.BillingPostalCode='33442';
        insert acc;        
        cnt = new Contact();
        cnt .FirstName = 'Test';
        cnt .LastName = 'Contact';
        cnt .Email = 'testcontact@gmail.com';
        cnt .Account = acc.Id;
        insert cont;
    }
con.IVR_Journey__c = cont.Id;  
       
insert con;
return con.id;
} 
   
}
I hope this solves your problems.

Please mark as best answer if it helps.

Thanks,
Balaji J
 
Miles Sonnenfeld 2Miles Sonnenfeld 2 
I have 4 tables that are associated with my opportunities.  Each of these need an accounting id to populate that increases in value as new records are created.  The format has been descided and can't be changed.  I want to create a APEX class (trigger will fire before/after insert) that will generate the next ID # (Project Agreement #) for that record.  The Project Agreement # must always have 3 digits (example: 001, 002, 003...010, etc)
1) get all records "Project Agreement #" where records match opportunity
2) Sort records decending and get first record
3) pull out string and convert to int
4) add 1 to int and convert back to 3 digit string format

My code is as follows....
Right now I am able to get a decensding list, however I can't pull the "0" record from the list and further just the "project_Agreement__c" field.

public class NewProjectExtension {
    public static void CreateExtension(String Carrier, id OpportunityID){
        
        if(Carrier=='1'){
            List<1Carrier_Sales__c> AgreementList = [SELECT Project_Agreement__c FROM 1Carrier_Sales__c WHERE Opportunity__c =: OpportunityID];
            AgreementList.sort();
            
            List<1Carrier_Sales__c> Desc_AgreementList = new List<1Carrier_Sales__c>();
            for(Integer i = AgreementList.size()-1;i>=0;i--){
                Desc_AgreementList.add(AgreementList[i]);
            
            }
            system.debug('Check Order -->'+Desc_AgreementList); //prints order of Project_Agreement__c
            
        }
    }
}

DEBUG LOG
18:32:43:017 USER_DEBUG [13]|DEBUG|Check Order -->(AT_T_Carrier_Sales__c:{Project_Agreement__c=004, Id=a0B2C0000007XpRUAU}, AT_T_Carrier_Sales__c:{Project_Agreement__c=003, Id=a0B2C0000007XpWUAU}, AT_T_Carrier_Sales__c:{Project_Agreement__c=002, Id=a0B2C0000007XpbUAE}, AT_T_Carrier_Sales__c:{Project_Agreement__c=001, Id=a0B2C0000007XpMUAU})
Best Answer chosen by Miles Sonnenfeld 2
Maharajan CMaharajan C
Hi Mlles,

Try the below changes to get the first value from list:

public class NewProjectExtension {
    public static void CreateExtension(String Carrier, id OpportunityID){
        
        if(Carrier=='1'){
            List<1Carrier_Sales__c> AgreementList = [SELECT Project_Agreement__c FROM 1Carrier_Sales__c WHERE Opportunity__c =: OpportunityID];
            AgreementList.sort();
            
            List<1Carrier_Sales__c> Desc_AgreementList = new List<1Carrier_Sales__c>();
            for(Integer i = AgreementList.size()-1;i>=0;i--){
                Desc_AgreementList.add(AgreementList[i]);
            
            }
            system.debug('Check Order -->'+Desc_AgreementList); //prints order of Project_Agreement__c

            Integer AddInt = Integer.ValueOf(Desc_AgreementList[0].Project_Agreement__c)+1;
            String str = String.ValueOf('00'+inte); //  In the above line the leading zeros will removed.
            system.debug('str --> ' + str); 


        }
    }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thank,
Raj