
Hi Guys,Welcome back, Today we discuss about Sample Gallery and how can we use sample gallery apps into our salesforce orgs.
Hi Guys, Today iam going to explain update lookup field, I have lot of developer faced this issue. Business case : Customer whats to update company(lookup) on expense__c based on another company__c(lookup) of object resource__c
trigger updatelookup on Expense__c (before Insert){
set regionsID = new set(); for(Expense__c expRep: Trigger.New){
regionsID.add(expRep.region__c);
}
map mapRegionToCompanyName = new map();
for(region__c Region : [select id,resource__r.company__c from region__c where id in:regionsID]){
mapRegionToCompanyName.put(region.id,region.resource__r.company__c);
}
for(Expense__c expRep: Trigger.New){
expRep.company__c = mapRegionToCompanyName.get(expRep.region__c);
}
}
@isTest
public class updatecootest {
static testmethod void myunittest(){
Region__c r = new Region__c(Name ='China');
insert r;
Company__c com = new Company__c(Name ='ForceLearn');
insert com;
Expense__c er = new Expense__c(Name='Travel',Region__c= r.id,Company__c= com.id);
insert er;
Expense__c erc = [SELECT Id, Company__c, name FROM Expense__c];
test.starttest();
update erc;
test.stopTest();
}
}
Hola !! , we have update lookup field
Download: SalesforceQA
Please comments us for more updates and share to other to help. Keep Visiting us for more updates Like us for more updates Fb Page : ForceLearn keep share to help others 😎 😎 😎