• Karan Kehar
  • NEWBIE
  • 155 Points
  • Member since 2019

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 27
    Replies
We have some archived .json data as below, could we use Developper Console to create records in Salesforce?
Thank you!
{
"opp": {
"method": "POST",
"url": "/services/data/v37.0/sobjects/Opportunity",
"referenceId": "Opportunitiesopp_78537",
"body": {
"REMigrationData__c": "21",
"CampaignId": "7010G000000oVlTQAU",
"ReceiptStatus__c": "Do Not Receipt",
"Fund__c": "z-2100-z-Area of Greatest Need",
"HistoricalBatchNumber__c": "2007-86",
"HistoricalGiftID__c": "2007-63945",
"CloseDate": "2007-03-08T00:00:00",
"Close_Gift_Date__c": "2007-03-08T00:00:00",
"Name": " Donation 3/8/2007 12:00:00 AM",
"Amount": 44.6000,
"RecordTypeId": "012F0000001DAEg",
"AccountId": "0010G000028JUVGQA4",
"StageName": "Posted",
"npe01__Do_Not_Automatically_Create_Payment__c": true,
"GiftCode__c": "z-MIMF",
"GiftSubtype__c": "z-Donation (one-off)",
"Type": "Cash",
"npsp__Acknowledgment_Status__c": "To Be Acknowledged",
"TaxReceiptsNPSP__Receiptable_Amount__c": 44.6,
"TaxReceiptsNPSP__ReceiptQueue__c": "",
"Description": "\r\n",
"OppPayment_Payment_Method__c": "Cash",
"AuthorizationCode__c": null
}
  • September 25, 2020
  • Like
  • 0
Hi, I have error "Invalid field nme for SObject AggregateResult"
From VisualForce Page 

Here is my apex controller
public class BatchListController {
    public Id venue {get; set;}
    
    Public List<Batch__c> Batches = new List<Batch__c>();   
    Public AggregateResult[] agr {get{
        return [SELECT Name nme, count(Job__r.Id) cntid, count(Job__r.Name) cntnme, max(BatchDate__c) cntdt, count(VenueBatch__r.Name) cntvn FROM Batch__c GROUP BY Name];
        
        
    } set;}
    
    Public BatchListController() {
        system.debug('==>JobListController  is calling==>');
        Batches = [SELECT Name,Job__r.Id, Job__r.Name, BatchDate__c, VenueBatch__r.Name FROM Batch__c];
        
    }
    public List<Batch__c>getBatches(){
        
        return Batches;
    }
    public List<Batch__c>setBatches(List<Batch__c>temp){
        
        Batches = temp;
        return Batches;
    }
}

And here is my visualforce page 

<apex:page controller = "BatchListController">
    
    <apex:form>
    
    <apex:PageBlock title="Batch List" id="Jobs_List" >
        
        <apex:pageBlockTable value = "{!agr}" var = "a">
             
            <apex:column style="width:350px" headerValue="Batch" value="{!a['nme']}"/>
            <apex:column style="width:350px" headerValue="#of Jobs " value="{!a['cntid']}"/>
            <apex:column style="width:350px" headerValue = "# of Venue " value="{!a['cntvn']}"/>
            <apex:column style="width:350px" headerValue = "Batch Date" value="{!a['cntdt']}"/>
        </apex:pageBlockTable>
        
        </apex:PageBlock>
        
        <apex:pageBlock title = "Work Order" id = "Work_Order">
        
        
            
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

I am dealing with this for an hour but I don't know where I am wrong. 
Thank you!!
Code is:

@isTest   
    public static void testMethod4(){
   
        Account acc1 =new Account();
        acc1.Name='Managal';
        insert acc1;
        
        Account acc2 =new Account();
        acc2.Name='Managala';
        insert acc2;
        
        contact con=new contact();
        con.lastname='Jyoti';
        con.firstname='Savalgi';
        con.AccountId=acc1.id;
        con.Tet_Contact_Pid__c = '060587-12949';
        insert con;
        
        AccountContactRelation Acctcr=
        new  AccountContactRelation(AccountId=acc2.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
                                
        insert Acctcr;
        
        Acctcr.Tet_IsPrimaryContact__c= True;
        update con;//Updated Primary to contact Sam
        
        Account acc3 =new Account();
        acc3.Name='Bibhu';
        insert acc3;
        
        Account acc4 =new Account();
        acc4.Name='Bibhudutta';
        insert acc4;
        
        contact con1=new contact();
        con1.lastname='Ankit';
        con1.firstname='Savalgi';
        con1.AccountId=acc3.id;
        con1.Tet_Contact_Pid__c = '200568-13106';
        insert con;
        
        AccountContactRelation Acctcr1=
        new  AccountContactRelation(AccountId=acc4.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
        insert Acctcr1;
        
        Acctcr1.Tet_IsPrimaryContact__c= True;
        update con1;//Updated Primary to contact Ankit
        
        con.Tet_Contact_Pid__c=con1.Tet_Contact_Pid__c;
        update con;
        system.debug('Value of 2nd contact is:' +con1.Tet_Contact_Pid__c);
        
    }
I'll preface this with the fact I am new to visualforce.

Is it possible to display picklist values on a visualforce page by recordtype using the standard controller (and optionally adding an extension)?

Currently picklist values load based on my default record type.

I would like to load the correct ones on the visualforce page, and additionally would like the option to change the record type on the visualforce page and have the picklists update with the correct options

I would like to do this using standard functionality ideally rather than load options via apex, or I would like to know that what I am trying to achieve is not possible.

Thanks

Tim

 
I want to test a class with an invocable method. Actually i get 51% Coverage and  at the line 73 in the Test class the error is:

"System.DmlException: Update failed. First exception on row 0 with id a03f0000006BbNwAAK; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Post Affiliate Inventory” process failed. Give your Salesforce admin these details. An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]
: []


I want to remind that this class is to copy all child records from an object to an other object when a criteria is meet in the parent record. 

Apex Class: 
public class PostToAffiliateInventory {
    
    @InvocableMethod(label ='post to affiliate inventory')
    
    public static void PosttoInv(list<Id> deliveryId){
        
        list <Container__c> con = new List <Container__c>();
        list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();
        list <Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
        list <Delivery__c> delList = [SELECT Id, Is_Posted_To_Affiliate_Inventory__c, Affiliate_Center__c,AffiliateCenterId__c, Automatic_Code__c  FROM Delivery__c WHERE Id in :deliveryId];
        
        Id containerRecordTypeCaracole = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id containerRecordTypePAPCRN = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id containerRecordTypeCanteenPAP = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Canteen_PAP').getRecordTypeId();
        id crt; 
        
        Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id ArticleContainerPAPCRN = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id ArticleContainerCanteenPAP = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('PAP_Canteen').getRecordTypeId();
        id ArticleContainerAdmin = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('Admin').getRecordTypeId();
        id acrt;
        
        Container__c c;
        
        for (Delivery__c d : delList){
            if (d.Is_Posted_To_Affiliate_Inventory__c){
                if(d.Affiliate_Center__c =='FFP Caracole'){
                    crt = containerRecordTypeCaracole;
                }else if(d.Affiliate_Center__c =='CRN PAP'){
                    crt = containerRecordTypePAPCRN;
                }else if(d.Affiliate_Center__c =='PAP Canteen'){
                    crt = containerRecordTypeCanteenPAP;
                }
                c = new  Container__c();
                c.Name = d.Automatic_Code__c;
                c.FFP_Centers__c = d.Affiliate_Center__c ;
                c.RecordTypeId = crt;
                c.Distribution_Center__c = d.AffiliateCenterId__c;
                c.Is_Owner_Shipper__c = 'No';
                c.Provenance__c = 'FFP PAP';
                c.Type__c = 'Food';
                c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
                c.Is_Automatic_Creation__c = TRUE;
                
                insert c;
                
                itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                            Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                            Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                            FROM Item_Distributed__c  where Delivery__c  =: d.id ];             
                
                for (Item_Distributed__c OrderItems: itemList){
                    Articles_Containers__c ac = new Articles_Containers__c();
                    if(c.FFP_Centers__c == 'FFP Caracole'){
                        acrt = ArticleContainerRecordTypeCaracole;
                    }else if(c.FFP_Centers__c == 'CRN PAP'){
                        acrt = ArticleContainerPAPCRN;
                    }else if (c.FFP_Centers__c == 'PAP Canteen'){
                        acrt = ArticleContainerCanteenPAP;
                    }else acrt = ArticleContainerAdmin;
                    
                    ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = acrt; 
                    ac.Container__c =c.Id;
                    ac.Product__c = OrderItems.Product__r.Product__r.Id;
                    ac.Number__c= 0;
                    ac.Quantity__c = OrderItems.Quantity__c;
                    ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                    ac.UM__c = OrderItems.Product__r.UM__c;
                    ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                    ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                    ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                    ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                    ac.DeliveryItemsReferences__c = OrderItems.id;
                    
                    contenairItems.add(ac);
                }      
                Insert contenairItems; 

            }
            
        } 
    }
}

Test Class: 
@IsTest
public class PostToAffiliateInventoryTest {
    
     @isTest static  void PostToAffiliateInv (){
        Account afc = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='FFP Caracole', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'NORD', Address__c ='Test Address');
        
        Account pa = new Account(Name ='Central Office', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='Central Office', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'OUEST', Address__c ='Test Address');
        
        insert pa;
   
        Product2 p = new Product2(Name ='TestProduct'); 
        insert p;
        Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
        insert cs;
        
        //Id containerRecordTypeCaracole =      Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        //Id containerRecordTypeCentralOffice = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Central Office').getRecordTypeId();
        Container__c c = new Container__c( Name = 'CMLU', Provenance__c='FFP FLORIDA', Statut__c='Open', Distribution_Center__c= pa.id, FFP_Centers__c = 'Central Office',  RecordTypeId='0126A000000nMlj',  Shipper__c=cs.Id );
        insert c;
        
       // Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
       // Id ArticleContainerRecordTypeCentralOffice = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('HT Central Office').getRecordTypeId();
        Articles_Containers__c ac = new Articles_Containers__c();   
        
        ac.Product__c=p.ID;
        ac.Unit_Weight__c = 45; 
        ac.Unit_Cost__c = 87;
        ac.Container__c= c.ID;
        ac.Number__c = 55;
        ac.UM__c ='UNIT(S)';    
        ac.Local_ID__c = 7888;
        ac.Comments__c = 'UNIT(S)';
        ac.Purpose__c='Consignment';
        ac.Condition__c= 'New';
        ac.FFP_Centers__c = 'Central Office';
        ac.RecordTypeId = '0126A0000019jRK';
        insert ac;
        
        Account a = new Account();
        a.Name ='test Account'; 
        a.Representant__c ='Bijou';
        a.Distribution_Center__c='Central Office';
        a.Class__c = 'NGO'; 
        a.Type = 'CLINICS';
        a.Departement__c = 'NORD';
        a.Address__c ='Test Address';
        a.ParentId = pa.ID;
        a.Affiliate_Center__c = afc.Id;
        insert a ;
       
        
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
       
        del.Is_Posted_To_Affiliate_Inventory__c = false;
        
        insert del;
        
        Item_Distributed__c itemDis = new Item_Distributed__c();
        itemDis.Quantity__c = 10;
        itemDis.Product__c = ac.Id;
        itemDis.Delivery__c =del.Id;
     
        insert itemDis;
        
        del.Is_Posted_To_Affiliate_Inventory__c = true;
        update del;
        
        
        List<Delivery__c> delivery_Obj  =  [SELECT Beneficiaire__c from Delivery__c];
        System.assertEquals(1,delivery_Obj.size());
        List<Item_Distributed__c> item_distributed_Obj  =  [SELECT Product__c,Quantity__c,Delivery__c from Item_Distributed__c];
        System.assertEquals(1,item_distributed_Obj.size());

        PostToAffiliateInventory pav = new PostToAffiliateInventory();
      
    }
    
}


 
Hi All,

I am trying to migrate Lightning Email Templates from one sandbox to another through Data Loader. I am able to retrieve the templates by filtering on the Folder ID. When I am trying to insert the templates in another sandbox by updating the folder ID, I get the below error.
 
"Templates used by other resources must remain in a folder other than your Personal template folder, and cannot be deleted or deactivated.: Folder ID"

Seems like it is due to the AccessType property on Folder which is set as Hidden. Not sure how to create a public lightning email template folder.

Any help on this would be appreciated.!
 
Hi All,

I am sending an email from Salesforce using SingleEmailMessage class but the email message record which is created has no value in the thread identifier field but it exists when sending email from standard send email button 
Hi All,

I am facing challenge in retreieving lightning email templates folder in vscode. I am aware that in order to retrieve classic email templates folder package.xml is like this:
<types>
        <members>foldername</members>
        <members>foldername/templatename</members>
        <name>EmailTemplate</name>
</types>

When I use this package.xml for lightning email templates folder, I am able to retrieve the templates but the folder throws error:
=== WARNING: The following metadata isn’t in your org. If it’s not new, someone deleted it from the org.
Entity of type 'EmailTemplate' named 'foldername' cannot be found

The difference b/w lightning email template folder and classic email template folder is type:

For classic folder it is Email but for lightning it is coming as EmailTemplate
Hi,

I have created a lightning component which has a lightning:duallistbox in it.Now when I select a value on the selected values list on the right side, I want a modal to be displayed which shows some sort of details of the selected value.
User-added imageFor example, in the above image when I select "test Redpath Sugar", I want to open a modal which shows some details of the selected entity. I have tried document.getElementsByClassName("slds-is-selected") which is returning array of 0 length.

Has anyone trying to achive this ? Any help would be greatly appreciated.

Thanks,
Karan
public class LeadHelper {
     public static void createContact(List<Lead> leadList){
        Id ContactRecordTypeId =  Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('New').getRecordTypeId();
        List<Contact> listAcc=new List<Contact>();
        for(Lead l : leadList){
            Contact acct = new Contact();
            acct.firstName = l.firstName;
             acct.LastName = l.lastname;
            acct.Email = l.Email;
            acct.MobilePhone = l.MobilePhone.Substring(2,l.MobilePhone.length());
            acct.RecordTypeId = ContactRecordTypeId;
            acct.Source__c = 'Facebook';
            acct.Project__c = l.Project__c;
            acct.BillingCity__c = l.City;
            acct.Ad_Name__c = l.Ad_Name__c;
            listAcc.add(acct);
        }
        system.debug('listAcc : ' + listAcc);
        insert listAcc;
    }
}
 
Hi All,

I am facing challenge in retreieving lightning email templates folder in vscode. I am aware that in order to retrieve classic email templates folder package.xml is like this:
<types>
        <members>foldername</members>
        <members>foldername/templatename</members>
        <name>EmailTemplate</name>
</types>

When I use this package.xml for lightning email templates folder, I am able to retrieve the templates but the folder throws error:
=== WARNING: The following metadata isn’t in your org. If it’s not new, someone deleted it from the org.
Entity of type 'EmailTemplate' named 'foldername' cannot be found

The difference b/w lightning email template folder and classic email template folder is type:

For classic folder it is Email but for lightning it is coming as EmailTemplate
We have some archived .json data as below, could we use Developper Console to create records in Salesforce?
Thank you!
{
"opp": {
"method": "POST",
"url": "/services/data/v37.0/sobjects/Opportunity",
"referenceId": "Opportunitiesopp_78537",
"body": {
"REMigrationData__c": "21",
"CampaignId": "7010G000000oVlTQAU",
"ReceiptStatus__c": "Do Not Receipt",
"Fund__c": "z-2100-z-Area of Greatest Need",
"HistoricalBatchNumber__c": "2007-86",
"HistoricalGiftID__c": "2007-63945",
"CloseDate": "2007-03-08T00:00:00",
"Close_Gift_Date__c": "2007-03-08T00:00:00",
"Name": " Donation 3/8/2007 12:00:00 AM",
"Amount": 44.6000,
"RecordTypeId": "012F0000001DAEg",
"AccountId": "0010G000028JUVGQA4",
"StageName": "Posted",
"npe01__Do_Not_Automatically_Create_Payment__c": true,
"GiftCode__c": "z-MIMF",
"GiftSubtype__c": "z-Donation (one-off)",
"Type": "Cash",
"npsp__Acknowledgment_Status__c": "To Be Acknowledged",
"TaxReceiptsNPSP__Receiptable_Amount__c": 44.6,
"TaxReceiptsNPSP__ReceiptQueue__c": "",
"Description": "\r\n",
"OppPayment_Payment_Method__c": "Cash",
"AuthorizationCode__c": null
}
  • September 25, 2020
  • Like
  • 0

Hi, I'm working on trigger that will [after insert] get Street from ContactPointAddress object connected via lookup (Contact__c) and re-write MailingStreet field in Contact object ONLY if checkbox isDefault is checked. This is what I've done so far:

public static void AfterInsert(ContactPointAddress[] lstContactPointAddresses)
		{
			List<Contact> allPassagersToBeUpdated= new List<Contact>();
			for (ContactPointAddress tmpContactPointAddress : lstContactPointAddresses)
				{
					// created contactPointAddress is checked - is default
					if (tmpContactPointAddress.IsDefault == true) {
						Contact passenger = [SELECT Name,LastName,MailingStreet FROM Contact WHERE Id =: tmpContactPointAddress.Contact__c];

						Address addressCompoundField = (Address)tmpContactPointAddress.Address;
						passenger.MailingStreet = addressCompoundField.Street;
						allPassagersToBeUpdated.add(passenger);

					}
					else {
						return;
					}

				}
			if(allPassagersToBeUpdated.size()>0){
				update allPassagersToBeUpdated;
			}

		}

The problem is, my compound field Addres in Contact Point Address is always null. I don't know why as I can acces values of other fields. Can anyone help me please? Thanks a lot:)
Hi, I have error "Invalid field nme for SObject AggregateResult"
From VisualForce Page 

Here is my apex controller
public class BatchListController {
    public Id venue {get; set;}
    
    Public List<Batch__c> Batches = new List<Batch__c>();   
    Public AggregateResult[] agr {get{
        return [SELECT Name nme, count(Job__r.Id) cntid, count(Job__r.Name) cntnme, max(BatchDate__c) cntdt, count(VenueBatch__r.Name) cntvn FROM Batch__c GROUP BY Name];
        
        
    } set;}
    
    Public BatchListController() {
        system.debug('==>JobListController  is calling==>');
        Batches = [SELECT Name,Job__r.Id, Job__r.Name, BatchDate__c, VenueBatch__r.Name FROM Batch__c];
        
    }
    public List<Batch__c>getBatches(){
        
        return Batches;
    }
    public List<Batch__c>setBatches(List<Batch__c>temp){
        
        Batches = temp;
        return Batches;
    }
}

And here is my visualforce page 

<apex:page controller = "BatchListController">
    
    <apex:form>
    
    <apex:PageBlock title="Batch List" id="Jobs_List" >
        
        <apex:pageBlockTable value = "{!agr}" var = "a">
             
            <apex:column style="width:350px" headerValue="Batch" value="{!a['nme']}"/>
            <apex:column style="width:350px" headerValue="#of Jobs " value="{!a['cntid']}"/>
            <apex:column style="width:350px" headerValue = "# of Venue " value="{!a['cntvn']}"/>
            <apex:column style="width:350px" headerValue = "Batch Date" value="{!a['cntdt']}"/>
        </apex:pageBlockTable>
        
        </apex:PageBlock>
        
        <apex:pageBlock title = "Work Order" id = "Work_Order">
        
        
            
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

I am dealing with this for an hour but I don't know where I am wrong. 
Thank you!!
When we change the language setting in Salesforce all the standard fields update to that language however all custom fields stay in english. How can we get the custom fields to update to the language selected
Hi community friends, need some help please !

Overview:
We are getting some Person Accounts to flow into SalesCloud from one of the external systems (Dynamics 365).

We are than using Process Builder to auto create “Leads” for these accounts (for reporting and marketing perspective) – PB seems to be working correctly fine here;

Requirement:
1: We want to automate these Leads (just these ones) to close as  ‘Converted’ upon creation; plus if possible

2: Have the opportunities to get auto created and close as ‘Closed – Won’ upon creation  – without creating an account (as the account already exists)

I am been trying to use a combination of the following Apex class and Trigger, but seems is not working as desired…. Would anyone be able to help me with this issue please ?

Apex Trigger:
Trigger AutoConvertLead on Lead(After Insert)
{
   For(Lead ld : trigger.new){
        //  calling apex class method to convert this lead
  AutoConvertLead.leadconversion(ld.id)
 }
    }

Apex Class:
Public class AutoConvertLead(){
     public static void leadConversion(string leadid){
        Database.LeadConvert Leadconvert = new Database.LeadConvert();
           // pass the leadId which need to be converted
        Leadconvert.setLeadId(leadid);
   LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
       Leadconvert.setConvertedStatus(convertStatus.MasterLabel);
        Leadconvert.setCreateOpportunity(True);
Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
System.assert(Leadconverts.isSuccess());
}
}


Thanks and regards,
Sunny


 
Can anyone suggest me best for Marketing Cloud material/videos/udemy courses?
Code is:

@isTest   
    public static void testMethod4(){
   
        Account acc1 =new Account();
        acc1.Name='Managal';
        insert acc1;
        
        Account acc2 =new Account();
        acc2.Name='Managala';
        insert acc2;
        
        contact con=new contact();
        con.lastname='Jyoti';
        con.firstname='Savalgi';
        con.AccountId=acc1.id;
        con.Tet_Contact_Pid__c = '060587-12949';
        insert con;
        
        AccountContactRelation Acctcr=
        new  AccountContactRelation(AccountId=acc2.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
                                
        insert Acctcr;
        
        Acctcr.Tet_IsPrimaryContact__c= True;
        update con;//Updated Primary to contact Sam
        
        Account acc3 =new Account();
        acc3.Name='Bibhu';
        insert acc3;
        
        Account acc4 =new Account();
        acc4.Name='Bibhudutta';
        insert acc4;
        
        contact con1=new contact();
        con1.lastname='Ankit';
        con1.firstname='Savalgi';
        con1.AccountId=acc3.id;
        con1.Tet_Contact_Pid__c = '200568-13106';
        insert con;
        
        AccountContactRelation Acctcr1=
        new  AccountContactRelation(AccountId=acc4.id,ContactId=con.id,Tet_IsPrimaryContact__c= True);
        insert Acctcr1;
        
        Acctcr1.Tet_IsPrimaryContact__c= True;
        update con1;//Updated Primary to contact Ankit
        
        con.Tet_Contact_Pid__c=con1.Tet_Contact_Pid__c;
        update con;
        system.debug('Value of 2nd contact is:' +con1.Tet_Contact_Pid__c);
        
    }
I'll preface this with the fact I am new to visualforce.

Is it possible to display picklist values on a visualforce page by recordtype using the standard controller (and optionally adding an extension)?

Currently picklist values load based on my default record type.

I would like to load the correct ones on the visualforce page, and additionally would like the option to change the record type on the visualforce page and have the picklists update with the correct options

I would like to do this using standard functionality ideally rather than load options via apex, or I would like to know that what I am trying to achieve is not possible.

Thanks

Tim

 
I want to test a class with an invocable method. Actually i get 51% Coverage and  at the line 73 in the Test class the error is:

"System.DmlException: Update failed. First exception on row 0 with id a03f0000006BbNwAAK; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Post Affiliate Inventory” process failed. Give your Salesforce admin these details. An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]
: []


I want to remind that this class is to copy all child records from an object to an other object when a criteria is meet in the parent record. 

Apex Class: 
public class PostToAffiliateInventory {
    
    @InvocableMethod(label ='post to affiliate inventory')
    
    public static void PosttoInv(list<Id> deliveryId){
        
        list <Container__c> con = new List <Container__c>();
        list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();
        list <Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
        list <Delivery__c> delList = [SELECT Id, Is_Posted_To_Affiliate_Inventory__c, Affiliate_Center__c,AffiliateCenterId__c, Automatic_Code__c  FROM Delivery__c WHERE Id in :deliveryId];
        
        Id containerRecordTypeCaracole = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id containerRecordTypePAPCRN = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id containerRecordTypeCanteenPAP = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Canteen_PAP').getRecordTypeId();
        id crt; 
        
        Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id ArticleContainerPAPCRN = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id ArticleContainerCanteenPAP = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('PAP_Canteen').getRecordTypeId();
        id ArticleContainerAdmin = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('Admin').getRecordTypeId();
        id acrt;
        
        Container__c c;
        
        for (Delivery__c d : delList){
            if (d.Is_Posted_To_Affiliate_Inventory__c){
                if(d.Affiliate_Center__c =='FFP Caracole'){
                    crt = containerRecordTypeCaracole;
                }else if(d.Affiliate_Center__c =='CRN PAP'){
                    crt = containerRecordTypePAPCRN;
                }else if(d.Affiliate_Center__c =='PAP Canteen'){
                    crt = containerRecordTypeCanteenPAP;
                }
                c = new  Container__c();
                c.Name = d.Automatic_Code__c;
                c.FFP_Centers__c = d.Affiliate_Center__c ;
                c.RecordTypeId = crt;
                c.Distribution_Center__c = d.AffiliateCenterId__c;
                c.Is_Owner_Shipper__c = 'No';
                c.Provenance__c = 'FFP PAP';
                c.Type__c = 'Food';
                c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
                c.Is_Automatic_Creation__c = TRUE;
                
                insert c;
                
                itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                            Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                            Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                            FROM Item_Distributed__c  where Delivery__c  =: d.id ];             
                
                for (Item_Distributed__c OrderItems: itemList){
                    Articles_Containers__c ac = new Articles_Containers__c();
                    if(c.FFP_Centers__c == 'FFP Caracole'){
                        acrt = ArticleContainerRecordTypeCaracole;
                    }else if(c.FFP_Centers__c == 'CRN PAP'){
                        acrt = ArticleContainerPAPCRN;
                    }else if (c.FFP_Centers__c == 'PAP Canteen'){
                        acrt = ArticleContainerCanteenPAP;
                    }else acrt = ArticleContainerAdmin;
                    
                    ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = acrt; 
                    ac.Container__c =c.Id;
                    ac.Product__c = OrderItems.Product__r.Product__r.Id;
                    ac.Number__c= 0;
                    ac.Quantity__c = OrderItems.Quantity__c;
                    ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                    ac.UM__c = OrderItems.Product__r.UM__c;
                    ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                    ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                    ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                    ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                    ac.DeliveryItemsReferences__c = OrderItems.id;
                    
                    contenairItems.add(ac);
                }      
                Insert contenairItems; 

            }
            
        } 
    }
}

Test Class: 
@IsTest
public class PostToAffiliateInventoryTest {
    
     @isTest static  void PostToAffiliateInv (){
        Account afc = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='FFP Caracole', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'NORD', Address__c ='Test Address');
        
        Account pa = new Account(Name ='Central Office', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='Central Office', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'OUEST', Address__c ='Test Address');
        
        insert pa;
   
        Product2 p = new Product2(Name ='TestProduct'); 
        insert p;
        Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
        insert cs;
        
        //Id containerRecordTypeCaracole =      Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        //Id containerRecordTypeCentralOffice = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Central Office').getRecordTypeId();
        Container__c c = new Container__c( Name = 'CMLU', Provenance__c='FFP FLORIDA', Statut__c='Open', Distribution_Center__c= pa.id, FFP_Centers__c = 'Central Office',  RecordTypeId='0126A000000nMlj',  Shipper__c=cs.Id );
        insert c;
        
       // Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
       // Id ArticleContainerRecordTypeCentralOffice = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('HT Central Office').getRecordTypeId();
        Articles_Containers__c ac = new Articles_Containers__c();   
        
        ac.Product__c=p.ID;
        ac.Unit_Weight__c = 45; 
        ac.Unit_Cost__c = 87;
        ac.Container__c= c.ID;
        ac.Number__c = 55;
        ac.UM__c ='UNIT(S)';    
        ac.Local_ID__c = 7888;
        ac.Comments__c = 'UNIT(S)';
        ac.Purpose__c='Consignment';
        ac.Condition__c= 'New';
        ac.FFP_Centers__c = 'Central Office';
        ac.RecordTypeId = '0126A0000019jRK';
        insert ac;
        
        Account a = new Account();
        a.Name ='test Account'; 
        a.Representant__c ='Bijou';
        a.Distribution_Center__c='Central Office';
        a.Class__c = 'NGO'; 
        a.Type = 'CLINICS';
        a.Departement__c = 'NORD';
        a.Address__c ='Test Address';
        a.ParentId = pa.ID;
        a.Affiliate_Center__c = afc.Id;
        insert a ;
       
        
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
       
        del.Is_Posted_To_Affiliate_Inventory__c = false;
        
        insert del;
        
        Item_Distributed__c itemDis = new Item_Distributed__c();
        itemDis.Quantity__c = 10;
        itemDis.Product__c = ac.Id;
        itemDis.Delivery__c =del.Id;
     
        insert itemDis;
        
        del.Is_Posted_To_Affiliate_Inventory__c = true;
        update del;
        
        
        List<Delivery__c> delivery_Obj  =  [SELECT Beneficiaire__c from Delivery__c];
        System.assertEquals(1,delivery_Obj.size());
        List<Item_Distributed__c> item_distributed_Obj  =  [SELECT Product__c,Quantity__c,Delivery__c from Item_Distributed__c];
        System.assertEquals(1,item_distributed_Obj.size());

        PostToAffiliateInventory pav = new PostToAffiliateInventory();
      
    }
    
}


 

There are two object A B
A is a master object of B
we have set a auto number in A which goes like con-0001,con-0002,...
then we want a auto branch number in B based on A which goes like con-0001-0001, con-0001-0002,... if they are related to con-0001

How can we make this happen in Apex or standard config?

I want to remove prefix 'Mr.' from my Account object. I have tried through the BatchApex class. But still its not working.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(account a:alist)
        {
           a.name= a.Name.removeStart('Mr.');
        }
        
        update alist;
        system.debug(alist);
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}
 
Hello, I'm trying to make a REST API callout, with the use of named credentials. However when I try to make the callout, I get a 502 error. Am I missing anything basic (this is my first callout :)

public class EMedCalloutsExtension {
    
    public final Lead referral;
    public String requestLabel;
        public String result {get;set;}
        public List<Object> emedData {get;set;}
    

     Public EMedCalloutsExtension(ApexPages.StandardController stdController){
        this.referral = (Lead)stdController.getRecord();

         
  }
       public Object  makePostCallout() {
    Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')]; 
           system.debug('***NAME OF REFERRAL***: '+ ref.firstname + ' ' + ref.lastname);
    String ssnReplace; 
           if (ref.Patient_SSN__c != null){
            ssnReplace = ref.Patient_SSN__c.replace('-','');
           }
    String genderLetter;
           if (ref.Gender__c == 'Male'){
               genderLetter = 'M';
           } else if (ref.Gender__c == 'Female'){
               genderLetter = 'F';
           }
           
           String first;
           String second;
           String third;
            String d = String.valueOf(ref.Patient_DOB__c);
           system.debug('***dob string raw: ' + d);
                first = d.substring(0,4);
                second = d.substring(5,7);
                third = d.substring(8,10);
           String dob = first + second + third;
           system.debug('***dob formatted: ' + dob);
           
           Map<string, string> patientInfoMap = new Map<string, string>();
                          patientInfoMap.put('social_security_number', ssnReplace);
                          patientInfoMap.put('birthdate', dob);
                          patientInfoMap.put('gender', genderLetter);
                          patientInfoMap.put('last_name', ref.lastname);
                          patientInfoMap.put('first_name', ref.firstname);
           List<Object> patientInfoList = new List<Object>();
           patientInfoList.add(patientInfoMap);
           
           JSONGenerator gen = JSON.createGenerator(true);   
            gen.writeStartObject();     
             gen.writeStringField('processing_mode', 'Realtime');
             gen.writeStringField('request_type', '270');
             gen.writeStringField('information_source_id', '1');
             gen.writeStringField('submitter_system_id', '2');
             gen.writeStringField('submitter_system_type', 'api');
             gen.writeStringField('submitter_request_id', 'R1');
                 gen.writeStringField('submitter_user_id', '3');
            gen.writeObjectField('subscribers', patientInfoList);
              gen.writeEndObject();   
         String jsonS = gen.getAsString();
        System.debug('***BODY:        '+jsonS);
          
       // Continuation con = new Continuation(40);
        //con.continuationMethod='processResponse';

       HttpRequest req = new HttpRequest();

req.setEndpoint('callout:Emed/');
   
        req.setHeader('ContentType', 'application/json'); 
  req.setHeader('Accept', 'application/json');         
System.debug('***HEADER:      ' + req.getHeader('Authorization'));
        req.setMethod('POST');
        req.setBody(jsonS);
       Http http = new Http();  
     HTTPResponse res = http.send(req);
                system.debug('Request: ' + req);

//print the header
    //get the list of header names (keys)
string[] headerkeys2 = res.getHeaderKeys();
//create an object to store your header key-value pairs
Map<string, string> headers2 = new map<string, string>();
//iterate through they keys, and populate your map
for(string s : headerkeys2){
   headers2.put(s,res.getHeader(s));
   system.debug('header of response: ' + s + ' value: ' + res.getHeader(s));
}

           
  String result = null;
    Integer statusCode = res.getStatusCode();
          system.debug('***statusCode is***: ' + statusCode);
   if(statusCode == 200){
             system.debug('***API invoked successfully***');
    result = res.getBody();
          system.debug('***RESULT***: ' + result);
      }   
           return result;   
        
    }
                                
 public Object processResponse() {  
        HttpResponse response = Continuation.getResponse(this.requestLabel);
 Integer statusCode = response.getStatusCode();
    system.debug('***statusCode is ***:' + statusCode);
        // Set the result variable that is displayed on the Visualforce page
        if (statusCode == 200) {
             system.debug('statusCode is ' + statusCode);
            this.result = response.getBody();
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            emedData = (List<Object>) results.get('emedData');
        }
        return null;
     
    }

}
Everytime I do an upsert to a detail custom  object which is related to Contact,
Contact   - Object1(master)-->Object2 (Detaill)

I get INVALID_FIELD_FOR_INSERT_UPDATE error.
Seems like for custom object, it doesn't consider the ID of the parent and master objects.
Not sure how to resolve this but I think if I merge the IDs it will create a unique ID that will allow me to insert.

Is it possible to merge 2 columns and set as External ID in an Upsert?
For example :
csv:
ID1 ID2
11 22

mapping.sdl
ID1 + ID2=ExternalID__c

Is that possible?

Thanks,
Precious