• Ashishk
  • NEWBIE
  • 240 Points
  • Member since 2010

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 68
    Replies
I'm trying to do something I think is pretty basic.  I want to run a nightly batch that will summarize all of the Closed Won Opportunites by Account.  (Forget the fact that these roll-up by default.  I'm actually doing something different enough where this won't work.)  We have tons of Opportunities and I need to do this in a nightly batch file.  I'm comfortable with batches cranking away on Opportunities, but how would I keep a running tab BY ACCOUNT given that a specific batch might not have all of the Opportunities associated with that Account?
I develop Apex Code, is Create Field.
That made by Metadata API..

A Object and B Object must have Only one master-detail Field, right?

I created Master(A)-Detail(B) Field in B Object. and

When I create Master-Detail Field, I want know Master-detail Field related to A Object.

How to get Master SObject Name of Master-Detail Field?
 
Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get('B__c').getDescribe().fields.getMap();
            for(Schema.SObjectField f : fieldMap.values()) {
                System.debug(f.getDescribe());
            }

I was execute code.
But I can't find Object A Name....
 
I can't get the following trigger to update the acount!

Can you pleas help me?
 
trigger UpdateMembershipLevelOnAccount on Contact (after update) {

	for(Contact con : Trigger.New) {
	List<Contact> conList;
	List<Contact> gm;
	List<Contact> sm;
	List<Contact> bm;
	String contactMembLevel;
	String accountMembLevel;

		conList = [Select ID, Member_Level__c, Account.Membership_Level_Text__c FROM Contact WHERE Account.Id = :con.Account.Id];
		
		if(conList.Size() <2 ){
			accountMembLevel = contactMembLevel;
		}

		else if(conList.Size() >1 ){


		for(Contact c: conList){
			contactMembLevel = con.Member_Level__c;
			accountMembLevel = con.Account.Membership_Level_Text__c;


			if(c.Member_Level__c == 'Gold'){
				gm.add(c);
				accountMembLevel = 'Gold';
			}
			else if(c.Member_Level__c == 'Silver'){
				sm.add(c);
				if(gm.size() <1 && sm.size() >0){
				accountMembLevel = 'Silver';
		}
					else {
				
				bm.add(c);
				accountMembLevel= 'Black';
			}
				}
				
				}
				
				}
}
}



 
my Apex code :
public static List<GenericObject__c> GetGenericObjectByAccount(String accountIds)
    {    
        Map<String, Schema.SObjectField> fldObjMap = schema.SObjectType.GenericObject__c .fields.getMap();
        List<Schema.SObjectField> fldObjMapValues = fldObjMap.values();

        String theQuery = GenerateFields(fldObjMapValues );

        // Finalize query string
        theQuery += ' FROM GenericObject__c WHERE Account__c in '  + accountIds ; 

    

        // Make dynamic call
        GenericObject__c[] accList = Database.query(theQuery);
        return accList;
    }
    

Test class :
 static testMethod void test_GetGenericObjectByAccount(){
    test.startTest();
    Account act=new Account();
        act.name='test';
        act.type='Industry';
        insert act;
        Opportunity opp=new opportunity();               
        opp.IsPrivate=true;
        opp.name='zensar test';
        opp.Description='description';
        opp.StageName='zen stage';
        opp.CloseDate=date.today();
        insert opp;
    GenericObject__c go=new GenericObject__c();
    go.Account__c=act.id;
    go.opportunity__c=opp.id;
    insert go;
    list<GenericObject__c > go1=[select id,name,account__c from GenericObject__c];
    //string theQuery = ' FROM GenericObject__c WHERE Account__c in '  + act.id; 
    //string query= 'Select a.Id, a.Name, a.OwnerId  from GenericObject__c a Where a.Account__C IN \''+ act.id+'\'';
    like no : 325   :DataHelper.GetGenericObjectByAccount(go.id );
    test.stopTest();
    }
Error : 
System.QueryException: expecting a colon, found 'go.id'
Stack TraceClass.DataHelper.GetGenericObjectByAccount: line 733, column 1
Class.DataHelper_test.test_GetGenericObjectByAccount: line 325, column 1

Please help me to resolve this issue 
How would you bulkify this trigger? I have a SOQL query in a loop and understand that to be a no no. Appreciate any help.
trigger CreateOnboardings on Zuora__SubscriptionRatePlan__c (before insert) {

	for (Zuora__SubscriptionRatePlan__c mysub : Trigger.new){

		Account myAccount = [SELECT Id, OwnerId, Name, Local_Listings__c, Reviews__c, LMEL__c, Social_Ads__c, Social_Posting__c, SEO__c, Website_Product__c FROM Account WHERE Id = :mysub.Zuora__Account__c LIMIT 1];

		// Local Marketing Essentials Lite
		if (mysub.Name.contains('Local Marketing Essentials Lite')){
		/*	Onboarding__c onb = new Onboarding__c();
			onb.Account__c = ________;
			onb.Name = 'Local Marketing Essentials Lite + ' + ________;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = ________;*/
			myAccount.LMEL__c = true;
		}

		// Marketing Essentials Pro
		if (mysub.Name.contains('Marketing Essentials Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;

			insert onb;
		}

		// Local Listings
		if (mysub.Name.contains('Local Listings Pro')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Local Listings + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000Fk7BQAS';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Local_Listings__c = true;

			insert onb;
		}

		// Engage
		if (mysub.Name.contains('Engage')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Engage + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMBQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Engage__c = true;

			insert onb;
		}

		// Reviews
		if (mysub.Name.contains('Reviews')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Reviews + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkM6QAK';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Reviews__c = true;

			insert onb;
		}

		// SEO
		if (mysub.Name.contains('SEO')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'SEO + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMVQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.SEO__c = true;

			insert onb;
		}

		// Social Ads
		if (mysub.Name.contains('Social Ads')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Ads + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMLQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Ads__c = true;

			insert onb;
		}

		// Social Posting
		if (mysub.Name.contains('Social Posting')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Social Posting + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMQQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Social_Posting__c = true;

			insert onb;
		}

		// Website
		if (mysub.Name.contains('Website')){
			Onboarding__c onb = new Onboarding__c();
			onb.Account__c = myAccount.Id;
			onb.Name = 'Website + ' + myAccount.Name;
			onb.RecordTypeId = '0121I000000FkMGQA0';
			onb.Sales_Rep__c = myAccount.OwnerId;
			onb.Status__c = 'Not Started';
			myAccount.Website_Product__c = true;

			insert onb;
		}
		update myAccount;
	}

}

 
Hi,

I am getting error  in browser console as "SyntaxError: Unexpected token :", and my action function is not getting called?

What could be the reason?
  • September 19, 2018
  • Like
  • 0
Salesforce files feature is not available in customer portal, there is not clear document saying the same.

So we tried the same, if it is possible or not. After lot of efforts figured out and also confirmed by salesforce support.

We cannot share salesforce files with portal users. 

Can we create email template which will work like stay -in- touch request update so that it can be work exactly same as stay in touch template but field will be customized.

        plz help me.

Hi,
I want to create delivery record on 1st of each month.
How we can do that?


Thanks
Guru
public without sharing class N_ContactImport_Table {
  @AuraEnabled public List<Column> columns;
    @AuraEnabled public List<ContactWrapper> contactWrapperList;
    @AuraEnabled public String cData;
    @AuraEnabled public String next_link;
    
    public class Column {
        @AuraEnabled public String data;
        @AuraEnabled public String type;
        @AuraEnabled public String title;
    }
    
    public class ContactWrapper {
        @AuraEnabled public Contact contact;
        @AuraEnabled public Integer rowNumber;
        @AuraEnabled public String id; //this refers to ConstantContact List ID.
    }
}
  • November 27, 2018
  • Like
  • 0
Example : i have a multi picklist with values A,B,C,D & have related table A1,B2,C3,D4 for each. if A & C are selected only its related A1 ,C3 table should be visible in visual force page. 
is it possible that "onSelect" of A & C from multi-picklist , table related (A1, C3) to it should be visible.
  • November 27, 2018
  • Like
  • 0
Hi,
In my Case the senarios is there is custom Object (investment) lookup with contact. In Custom Object when status field is update i have to update account field. 
To make that thing possible i have to query account field in custom object trigger but i am not able to fetch accounts field.
Can please someone help how do i do that.

Thanks 
PR
  • November 25, 2018
  • Like
  • 0
Our organization has been in dire need of being able to convert a multi-select picklist value on our Case into text fields. We've discovered we can split the array by ';', though we're seeing multiple ways people have done it and are not able to create a working trigger. We are hoping to limit the trigger based on the record type, 'Applications', but could simply limit the trigger based on the multi-select picklist being blank, though not sure about a simple way to do that. We are trying to populate the text field: S1_High_School_Electives__c with the potentially multiple values of High_School_Electives_Desired__c. I tried manipulating the code from https://developer.salesforce.com/forums?communityId=09aF00000004HMGIA2#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000B1n0IAC

I'm not sure if I also need to create the class like that post has, and how that would be embedded in the trigger. The error I get is that a DML statement cannot operate on a trigger.new. I'm thinking a SOQL query could be made instead as well.
trigger UpdateHSElectivesMSPV1 on Case (after update) {



for(Case c : Trigger.new) {
String pickValuesStr;
    if(!String.isBlank(c.High_School_Electives_Desired__c)){
        List<String> pickValues = c.High_School_Electives_Desired__c.split(';');
        for(String str : pickValues){
            if(String.isBlank(pickValuesStr)){
                pickValuesStr = str;
                }
                 else{
                     pickValuesStr = pickValuesStr + '\n' + str;
                    } 
                }
            
  c.S1_High_School_Electives__c = pickValuesStr;

}

  Update c;
  }
  }

 
I have this code below - After inserting a new record, the values are getting overridden with another value as an after update is fired as soon as an after insert operation is complete.

As seen in the log 

trigger TPI_Update_MCCP_Prod_GoalEdit_on_MCCP on MC_Cycle_Plan_Product_vod__c (after update, after insert) {
    
    set<Id> prod_id=new set<Id>();
    set<Id> channel_id=new set<Id>();
    List<Id> target_id=new List<Id>();
    set<Id> target_id2=new set<Id>();   
    set<Id> plan_id=new set<Id>();
    set<Id> channel_id1=new set<Id>();
    set<Id> prod_id1=new set<Id>();
    decimal before_val;
    decimal after_val;
    string prod_name;
    AggregateResult[] groupedResults;
    integer aggregated_goal_val;
    decimal old_goal_val;
    decimal new_goal_val;
    set<Id> sum = new Set<Id>();
    boolean flag;
   
    List<MC_Cycle_Plan_vod__c> mcptoUpdate = New List<MC_Cycle_Plan_vod__c>();
    //    
    //hold value of products edited in set 'prod_id'
    //    
    for (MC_Cycle_Plan_Product_vod__c p: trigger.new)
    {      
        if(trigger.isInsert)
        {
            prod_name = Trigger.newMap.get(p.id).Product_Name_vod__c;          
            new_goal_val = Trigger.newMap.get(p.Id).Product_Activity_Goal_vod__c;  
            flag = true;
        }
        else if(trigger.isUpdate){
            old_goal_val = Trigger.oldMap.get(p.Id).Product_Activity_Goal_vod__c;
            prod_name = Trigger.oldMap.get(p.id).Product_Name_vod__c;
            new_goal_val = Trigger.newMap.get(p.Id).Product_Activity_Goal_vod__c;
            flag=false;
        }
        //        
        prod_id.add(p.id);        
        //      
        system.debug('MCCP product - ' + prod_id);
        System.debug('Old value of MCCP product - '+old_goal_val);
        //
        //hold values of channels related to products in set 'channel_id' where channel is 'Interaction'
        //      
        if(p.Channel_vod__c=='Interaction')
        {
            channel_id.add(p.Cycle_Plan_Channel_vod__c);
            system.debug('MCCP channel - ' + channel_id); 
        }
        //
        //hold values of target in 'target_id'
        //       
        List<MC_Cycle_Plan_Channel_vod__c> t= [select Cycle_Plan_Target_vod__c from MC_Cycle_Plan_Channel_vod__c where Id IN: channel_id];
        for (MC_Cycle_Plan_Channel_vod__c mc : t)
        {
            target_id.add(mc.Cycle_Plan_Target_vod__c);
        }
        system.debug('MCCP Target - ' + target_id);
        //
        //hold values of plan in 'plan_id'
        //      
        List<MC_Cycle_Plan_Target_vod__c> t2 = [select id,Cycle_Plan_vod__r.id from MC_Cycle_Plan_Target_vod__c where  Id IN : target_id];        
        for (MC_Cycle_Plan_Target_vod__c mc2 : t2)
        {
            plan_id.add(mc2.Cycle_Plan_vod__r.id);  
        }
        system.debug('MC Cycle Plan - ' + plan_id); 
        //
        //hold values of all target in 'target_id2'
        // 
        List<MC_Cycle_Plan_Target_vod__c> plan_1 = [select id from MC_Cycle_Plan_Target_vod__c where Cycle_Plan_vod__c in : plan_id];        
        for (MC_Cycle_Plan_Target_vod__c mc3 : plan_1)
        {
            target_id2.add(mc3.id);  
        }
        //
        //hold values of all channels of above targets where channel is 'Interaction' in 'channel_id1'
        // 
        system.debug('All MCCP Targets of above MC Cycle Plan - ' + target_id2);         
        List<MC_Cycle_Plan_Channel_vod__c> t3 = [select id,Channel_vod__c from MC_Cycle_Plan_Channel_vod__c where  Cycle_Plan_Target_vod__c IN : target_id2];       
        for (MC_Cycle_Plan_Channel_vod__c mc4 : t3)
        {
            if(mc4.Channel_vod__c=='Interaction'){
                channel_id1.add(mc4.id);  
            }            
        }
        system.debug('All MCCP Channels of above MCCP Target - ' + channel_id1);
        //    
        //hold value of products edited in set 'prod_id'
        //        
        List<MC_Cycle_Plan_Product_vod__c>  p1  = [select id,Product_Activity_Goal_vod__c from MC_Cycle_Plan_Product_vod__c where Cycle_Plan_Channel_vod__c in : channel_id1];
        
        for (MC_Cycle_Plan_Product_vod__c mc5 : p1)
        {
            prod_id1.add(mc5.id);
        }       
        system.debug('All MCCP Products of above MCCP Channels - '+ prod_id1);
        Set<id> result = prod_id1.clone();       
        system.debug('Removing the product where the value of goal is changed - ' + result.removeall(prod_id));
        system.debug('Resulting set of products where goal is not changed -'+result);
        List<MC_Cycle_Plan_Product_vod__c> mcp1 =[select Product_Name_vod__c from MC_Cycle_Plan_Product_vod__c where Id in: result];
        System.debug(mcp1.size());        
        //
        //     Aggregation of goals grouped by product with no change is stored in 'groupedResults'   
        //                               
        for(MC_Cycle_Plan_Product_vod__c aq : mcp1)
        {        
            if(aq.Product_Name_vod__c ==prod_name)
            {
                sum.add(aq.id);                
            }
        }    
        System.debug('Sum'+sum);
        groupedResults = [SELECT SUM(Product_Activity_Goal_vod__c)aver FROM MC_Cycle_Plan_Product_vod__c where Id in : sum]; 
        system.debug('Sum of goals grouped by product with no change - ' + integer.valueOf(groupedResults[0].get('aver')) );       
        //
        // typecasting the result into integer data type (aggregated_goal_val = total of all goals which are not edited)
        //         
        aggregated_goal_val  = integer.valueOf(groupedResults[0].get('aver')); 
        System.debug('Aggregated_goal_val in Insert - '+aggregated_goal_val);
        //
        //Old sum of goals (edited and non edited) grouped by product
        //
        system.debug('xxx'+trigger.isInsert);
        system.debug('xxx'+trigger.isUpdate);
        if(flag)
        {          
            before_val = aggregated_goal_val; 
            System.debug('Before Value in Insert - '+before_val);
            System.debug('Aggregated_goal_val in Insert - '+aggregated_goal_val);
        }
        else
        {
            before_val = aggregated_goal_val + old_goal_val;
            system.debug('Old value of edit goals -'+before_val);
        }
        //
        //New sum of goals (edited and non edited) grouped by product
        //
        after_val= aggregated_goal_val + new_goal_val;
        system.debug('New value of edit goals -'+after_val);
    }   
    List<MC_Cycle_Plan_vod__c> mcp =[select Product_1_TPI__c,Product_2_TPI__c,Product_3_TPI__c,Product_4_TPI__c,HQ_Target_1_TPI__c,HQ_Target_2_TPI__c,HQ_Target_3_TPI__c,HQ_Target_4_TPI__c,Proposed_Target_1_TPI__c,Proposed_Target_2_TPI__c,Proposed_Target_3_TPI__c,Proposed_Target_4_TPI__c from MC_Cycle_Plan_vod__c Where Id IN :plan_id];       
    for(MC_Cycle_Plan_vod__c mc:mcp){     
        for(MC_Cycle_Plan_Product_vod__c cyclprod : [Select Product_Name_vod__c from MC_Cycle_Plan_Product_vod__c WHERE ID =:prod_id]){                       
            if (mc.Product_1_TPI__c ==  ''){
                System.debug('Inserting in 1st prod');
                mc.Product_1_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_1_TPI__c = before_val;
                mc.Proposed_Target_1_TPI__c = after_val;
            }
            else if (mc.Product_1_TPI__c != '' && mc.Product_1_TPI__c == cyclprod.Product_Name_vod__c) 
            {
                System.debug('Updating in 1st prod');
                mc.Product_1_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_1_TPI__c = before_val;
                mc.Proposed_Target_1_TPI__c = after_val;
                system.debug('satisfy 1');
            }               
            else if (mc.Product_2_TPI__c == '')
            {
                System.debug('Inserting in 2nd prod');
                mc.Product_2_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_2_TPI__c = before_val;
                mc.Proposed_Target_2_TPI__c = after_val;
                system.debug('satisfy 2');
            }           
            else if (mc.Product_2_TPI__c != '' && mc.Product_2_TPI__c == cyclprod.Product_Name_vod__c)
            {
                System.debug('Updating in 2nd prod');         
                mc.Product_2_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_2_TPI__c = before_val;
                mc.Proposed_Target_2_TPI__c = after_val;
            }           
            else if (mc.Product_3_TPI__c == '')
            {
                System.debug('Inserting in 3rd prod');
                mc.Product_3_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_3_TPI__c = before_val;
                mc.Proposed_Target_3_TPI__c = after_val;                   
            }               
            else if (mc.Product_3_TPI__c != '' && mc.Product_3_TPI__c == cyclprod.Product_Name_vod__c)
            {
                System.debug('Updating in 3rd prod');
                mc.Product_3_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_3_TPI__c = before_val;
                mc.Proposed_Target_3_TPI__c = after_val;
            } 
            
            else if (mc.Product_4_TPI__c == '')
            {
                System.debug('Inserting in 4th prod');
                mc.Product_4_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_4_TPI__c = before_val;
                mc.Proposed_Target_4_TPI__c = after_val;                    
            }   
            else if (mc.Product_4_TPI__c != '' && mc.Product_4_TPI__c == cyclprod.Product_Name_vod__c)
            {
                System.debug('Inserting in 4th prod');
                mc.Product_4_TPI__c = cyclprod.Product_Name_vod__c;
                mc.HQ_Target_4_TPI__c = before_val;
                mc.Proposed_Target_4_TPI__c = after_val;   
            }           
        }
        mcptoUpdate.add(mc);
    }
    try{
        update mcptoUpdate;
        system.debug('\n mc cycle plan after update -> '+mcptoUpdate);
    }
    catch(Exception ex){
        System.debug('\n exception aa => '+ex.getMessage());
    }      
}
How to add button in listview console remedyforce
Hi Everyone,

I stuck at one place and could not able to resolve the issue.I know what is the issue and where its happening still I am clueless.Actually I am getting System.NullPointerException: Argument cannot be null in Test Class.

Below is my class:
 
01global with sharing class Audit {
02     
03    global String created_by;
04    global String reason;
05    global String requested_by_customer;
06    global String requested_by_type;
07    // Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
08    global Long requested_datetime;
09    global String requested_method;
10    global String others;
11    global String source_system;
12     
13     
14    global Consent_History__c getConsentHistory() {
15        Consent_History__c consentHistory = newConsent_History__c();
16         
17        consentHistory.Consent_Change_Created_By__c= this.created_by;
18        consentHistory.Change_Reason__c =this.reason;
19        consentHistory.Consent_Change_Requested_By_Customer__c= this.requested_by_customer;
20        consentHistory.Change_Received_From_Type__c= this.requested_by_type;
21        consentHistory.Change_Received_DateTime__c= DateTime.newInstance(this.requested_datetime);
22        consentHistory.Change_Received_Method__c= this.requested_method;
23        consentHistory.Consent_Change_Others__c =this.others;
24        consentHistory.Source_System__c =this.source_system;
25         
26        return consentHistory;
27    }
28}
Below is my test class:
01@isTest
02private class AuditTest {
03 
04    static testMethod void getConsentHistory() {
05       
06        Datetime myDate=System.now();
07         
08        Consent_History__c consentHistory = newConsent_History__c();
09       
10        consentHistory.Consent_Change_Created_By__c= 'User1@cochlear.com';
11        consentHistory.Change_Reason__c ='Test';
12        consentHistory.Consent_Change_Requested_By_Customer__c= 'Customer1';
13        consentHistory.Change_Received_From_Type__c='Professional';
14        consentHistory.Change_Received_DateTime__c= myDate;
15        consentHistory.Change_Received_Method__c= 'Consent Card';
16        consentHistory.Consent_Change_Others__c ='Consent Test';
17        consentHistory.Source_System__c=Constants.SYSTEM_MCP;
18       insert consentHistory;
19         
20       Test.startTest();
21       
22       Audit audit=new Audit();
23       audit.getConsentHistory();
24       Test.stopTest();
25         
26    }
27   
28}
I am receiving error at below line in class:
1consentHistory.Change_Received_DateTime__c =DateTime.newInstance(this.requested_datetime);
and below line in test class:
1audit.getConsentHistory();
I understand that there is something which I am not able to catch for date time in above class which results in returning null value.

Kindly help me to pass this error in my test class.

Any help will be greatly appreciated.

Many thanks in advance

Thanks & Regards,
Maria
Hello folks , 
Requirement:  Can any one tell me how to write a trigger on contact to check the duplicates for Name , phone , email . if any duplicate arises we need to put error message . condition is (Name OR phone OR Email).

trigger DuplicateTwoFieldsContact on Contact (before insert,before update) 
{
 if(trigger.isBefore)
 {
  map<String,Contact> mapcontact = new map<String,Contact>();
   map<String,Contact> phonemap = new map<String,Contact>();
  
  for(contact con: trigger.new) 
   {
   if(                                                 
   ((con.Email != null) && (Trigger.isInsert || con.email != trigger.oldmap.get(con.id).email )) ||
    ((con.Phone != null) && (Trigger.isInsert || con.Phone != trigger.oldmap.get(con.id).Phone ))
    )
     {                                
     if( !mapcontact.containskey(con.Email) || !phonemap.containskey(con.Phone))
      {
      mapcontact.put(con.Email ,con);
      phonemap.put(con.Phone ,con);
      
      } 
     }
   }
 
 for(contact c:[select id ,Email ,Phone from contact where Email =: mapcontact.keyset() OR Phone =: phonemap.keyset() ])
 {
 contact newcontact = mapcontact.get(c.Email);
  newcontact.Email.adderror('Duplicate Email has been detected ');
 
 contact Phonecontact = phonemap.get(c.Phone);
  Phonecontact.Phone.adderror('Duplicate Phone has been detected ');
 
 }
 }
}
Hi All, 
I have written an send email Functionality to send two different quote template based on the selected Template.

I passed the VF Constructor in Page Button. Sometimes its working fine and  some time it is not working Properly(Email is not triggering from salesforce just inserting the attachment in Salesforce )

Kindly assist me on this.It's very urgent kindly help me on this

MY Apex Class:
public class GenerateQuoteSpec{

    Public string QuoteId;
    public Quote Quot = new Quote();
    public Quote getQuot() { return Quot; }
    public Quote Quotedata= new Quote();
    public Blob content;
    string Contentname;
    string Contentname1;
    public Contact con { get; set; }
    public String subject { get; set; }
    public String emailbody { get; set; }
    public string CC{get;set;}
    List<String> CCAddress = new List<String>();
    
        
    public GenerateQuoteSpec(ApexPages.StandardController controller) {
        QuoteId = ApexPages.currentPage().getParameters().get('id');
        
        Quotedata= [select id,Name,Customer_name__c,QuoteNumber,Email,Letter_Head_New__c, Project_Type__c,ContactId from Quote where id =: QuoteID];         
           
           
      
        subject = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
        emailbody = 'Greetings from Ankidyne!\n\nPlease find the quotation for our products. kindly approve our quotation to serve your organization.\n\nPlease Check the Quote Pdf attached for further information.\n\n';
    }

    public void generatepdf(){
        try {
            Contentname = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
            Contentname1 = 'Ankidyne Quotation for '+Quotedata.Project_Type__c +' '+'('+ Quotedata.QuoteNumber+')';
            pageReference pdfpage;
            if(Quot.Quote_With_Tech_Spec__c == true) {
                system.debug('QuoteId'+QuoteId);
                pdfpage = page.GST_Image_Discount;
            }
             if(Quot.Quote_Without_Tech_Spec__c== true) { 
                system.debug('QuoteId'+QuoteId);
                pdfpage = page.GST_No_Discount;
            }
            pdfpage.getParameters().put('id',QuoteId);
            pdfpage.setRedirect(true);
            content = pdfpage.getcontent();
            Attachment att = new Attachment(ParentId=QuoteId, Body=content, ContentType='.pdf');
            // save this content in attachment
            if(Quot.Quote_With_Tech_Spec__c == true) {
                att.Name = Contentname;
            } if(Quot.Quote_Without_Tech_Spec__c== true) {
                att.Name = Contentname1;
            }
            insert att;
        }
        catch(exception ex) {
            apexpages.Message emsg = new apexpages.Message(apexpages.severity.WARNING,ex.getmessage());
            ApexPages.addMessage(emsg);
        }
    } 
    
    public pagereference save() {
        if((Quot.Quote_With_Tech_Spec__c == false && Quot.Quote_Without_Tech_Spec__c == false) || 
                (Quot.Quote_With_Tech_Spec__c == true && Quot.Quote_Without_Tech_Spec__c == true)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please select one option to continue'));
            return null;
        }
        generatepdf();
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }  
    
    public pagereference saveandsend() {
    
     con =  [select ID,Email,Email_Additional__c,CCEmail__c from Contact where ID=:Quotedata.ContactId] ; 
     
        if((Quot.Quote_With_Tech_Spec__c == false && Quot.Quote_Without_Tech_Spec__c == false) || 
                (Quot.Quote_With_Tech_Spec__c == true && Quot.Quote_Without_Tech_Spec__c == true)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please select one option to continue'));
            return null;
        }
        generatepdf(); 
        string[] Emailaddr = new string[]{};
        String[] ccAddresses = new String[]{};
        IF(CC!=Null || CC!='')
        {
        CCAddress=CC.split(',');
        }
        IF(con.Email!=Null || con.Email!='' || con.Email_Additional__c!=Null || con.Email_Additional__c!=''){
        Emailaddr.add(con.Email);
        Emailaddr.add(con.Email_Additional__c);
       }
        try {
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setFileName(Contentname+'.pdf');
            attach.setBody(content);
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(Emailaddr);
            email.setBccSender(true);
            email.setccAddresses(CCAddress);
            system.debug(emailbody);
            emailbody = emailbody.replace('\n','<br>');
            system.debug(emailbody);
            email.setSubject(Contentname);
            email.setHtmlBody(emailbody);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {attach}); 
            system.debug('QuoteContactId' + con);
            
            // Send the email
             Messaging.SendEmailResult [] sendResult  = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
            
           } Catch(Exception ex){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'The Email Address Provided in the contact information is not valid one and the Email address is:'+ex.getmessage()));
        }
        
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }
    
    public pagereference cancel() {
        pageReference returnpage = new pageReference('/'+QuoteId);
        return returnpage;
    }         
}




 
Hi
I am testing my visualforce & apex coding skills .
I have implemented a extension class with standard controller to mimic the functionality of SAVE , SAVE&NEW and QUICKSAVE.
public with sharing class MimicSaveQuickSave {

    ApexPages.StandardController sController;
    
    public MimicSaveQuickSave(ApexPages.StandardController stdcontroller) {

         sController=stdcontroller;
         
    }

    public PageReference saveAndNew()
   {
   
      sController.save();
      PageReference pref=new PageReference('/003/o');
      pref.setRedirect(true);
      
      return pref;
   }
 }
<apex:page standardController="Contact" extensions="MimicSaveQuickSave">
  <apex:form >
  
    <apex:pageBlock title="My Content" mode="edit">
    
      <apex:pageBlockButtons >
      
        <apex:commandButton action="{!save}" 
                            value="Save"/>
                            
      <apex:commandButton action="{!QuickSave}" 
                            value="QuickSave"/> 

       <apex:commandButton action="{!saveAndNew}" 
                            value="SaveAndNew"/>
                            
       <apex:commandButton action="{!cancel}" 
                            value="cancel"/>

      </apex:pageBlockButtons>
      
      <apex:pageBlockSection title="My Content Section" columns="2">
        <apex:inputField value="{!contact.firstname}"/>
        <apex:inputField value="{!contact.lastname}"/>
       </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
The SAVE &  SAVE&NEW is working but I am unable to code for QUICKSAVE
a) when I click SAVE&NEW button is it possible to redirect to the same visualforce page, so the enduser can enter the input values again.
b) how to implement QUICKSAVE functionality

Pls help me out

Thanks
sheila

 
Hello , 

Need your help or advice on the e below use case :

We have thousands of Leads in our system , we are building a process to reduce them piling up and also perform a clean up activity.

As part of the process to reduce the Leads from piling up , whenever an account(source of this can be an external system) is created in our SF instance , we are actualy planning to see if we have any existing lead(with filters on some fields) and convert that lead by linking the new account created to this Lead and updating Closed Reason(Custom Field on Lead) and also to skip creating the contact.

 Below are some of the issues that i am facing when trying to implement the above process.

Scenario 1 : Tried to invoke the Leadconvert operation but facing the below issues with this.
1. Unable to skip Creation of Contact on Lead Conversion
2.Unable to set value to Custom Field of Lead upon Conversion.


Scenario 2 :   As i need to skip the contact from creation and also update the custom fields of leads while linking this to a newly created account , tried to perform the Update operation on the Lead ,  by setting the ConvertedAccountID and Custom field values to desired values. but facing the below challenges.
1. Unable to set the ConvertedAccountID , as it was readonly field.

If any one faced  such scenarios and if you are able to progress with some workaround , Please let me know.

Any help or pointers on this would be highly appreciated.
 
I'm trying to do something I think is pretty basic.  I want to run a nightly batch that will summarize all of the Closed Won Opportunites by Account.  (Forget the fact that these roll-up by default.  I'm actually doing something different enough where this won't work.)  We have tons of Opportunities and I need to do this in a nightly batch file.  I'm comfortable with batches cranking away on Opportunities, but how would I keep a running tab BY ACCOUNT given that a specific batch might not have all of the Opportunities associated with that Account?
Hi Experts,

I need to calculate two fieds which are decimals of place  0(1,0). now my requriment is that when Week__c/frequency__c output is 1.0,2.0 it should allow only 0 decimal place if not it should not allow in the loop. eg:output is 6.0 it should allow in the loop if the output is 6.1 it should not. can anyone help me pls.
thanks in advance
Hi,
I have written the following soql query for fetching the last created record.

SELECT id, name,Body,parentID FROM Attachment order by CreatedDate DESC limit 1

But I am getting this error. Please help me. Thanks in advance.

System.QueryException : Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.

Hi

I have a custom object with a master detail relationship to the Contact object. 

I would like to have, on the custom object's record detail page, a list of all other records for that custom object's record that are related to the linked contact. 
Like a related list, but for records on the same object, not a child object.

I found a way to show a related list for another object linked to the contact, but not on the same object
<apex:page standardcontroller="app__c">
<apex:relatedList subject="{!app__c.Contact__c}" list="apps"/>
</apex:page>

Org is still in Classic

I can't get the following trigger to update the acount!

Can you pleas help me?
 
trigger UpdateMembershipLevelOnAccount on Contact (after update) {

	for(Contact con : Trigger.New) {
	List<Contact> conList;
	List<Contact> gm;
	List<Contact> sm;
	List<Contact> bm;
	String contactMembLevel;
	String accountMembLevel;

		conList = [Select ID, Member_Level__c, Account.Membership_Level_Text__c FROM Contact WHERE Account.Id = :con.Account.Id];
		
		if(conList.Size() <2 ){
			accountMembLevel = contactMembLevel;
		}

		else if(conList.Size() >1 ){


		for(Contact c: conList){
			contactMembLevel = con.Member_Level__c;
			accountMembLevel = con.Account.Membership_Level_Text__c;


			if(c.Member_Level__c == 'Gold'){
				gm.add(c);
				accountMembLevel = 'Gold';
			}
			else if(c.Member_Level__c == 'Silver'){
				sm.add(c);
				if(gm.size() <1 && sm.size() >0){
				accountMembLevel = 'Silver';
		}
					else {
				
				bm.add(c);
				accountMembLevel= 'Black';
			}
				}
				
				}
				
				}
}
}