-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
7Replies
How to prepopulate a Lookup field in VisualForce page?
I'm a little bit stuck at a point to prepopulate a Name from the Contact Object into a Custom Object. Situation: I have a VF page that I use to create new records, I replaced the SF standard NEW button with a custom VF page. In this VF Page there is a LookUp to the Contacts Object but I don't want Users to select the contact from the LookUp. Instead I want to auto-populate the User Name in the Contact field.
I searched for answers but I couldn't find anything. Hope somebody can help me! Below you can find the code snippet of the controller:
public class CreateMultipleVGAvailability{ public String VGAvailabilityLink{ get{ String VGAvailabilityLink = URL.getSalesforceBaseUrl().toExternalForm() + '/a3R/o' ; return VGAvailabilityLink; } } public VG_Availability__c MasterAvailability; public CreateMultipleVGAvailability(ApexPages.StandardController stdController) { this.MasterAvailability = (VG_Availability__c)stdController.getRecord(); } public void CreateVGAvailabilities(){ List<VG_Availability__c> NewAvailabilities = new list<VG_Availability__c>(); String DifferentDates = Apexpages.currentPage().getParameters().get('dates'); String Message; String ContactDateCombination; List<String> Dates = DifferentDates.split(', '); for(String D: Dates){ Date myDate = date.parse(D); VG_Availability__c NewRecord = new VG_Availability__c(); NewRecord.contact__c = MasterAvailability.contact__c; NewRecord.Is_Available__c = MasterAvailability.Is_Available__c; NewRecord.Comments__c = MasterAvailability.Comments__c; NewRecord.Date__c = myDate; ContactDateCombination = string.valueof(NewRecord.contact__c) + string.valueof(myDate); AggregateResult[] ContactDateCombinationAmount = [SELECT count(Id) Amount FROM VG_Availability__c WHERE ContactDateCombination__c =: ContactDateCombination]; if( ContactDateCombinationAmount[0].get('Amount') != 1){ NewAvailabilities.add(Newrecord); }else{ if(Message == Null){ Message = myDate + ', '; }else{ Message = Message + myDate + ', '; } } } if(Message != Null){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.'); ApexPages.addMessage(myMsg); } Insert(NewAvailabilities); } }
- Rachid El Kaddouri
- September 09, 2014
- Like
- 0
apex class fetch data from related list from Custom Object
I'm stuck at this one. I'm trying to fetch fields from a related list but this ain't working for a custom object. This is my situation:
The Object Account has a related list that links to a child Custom Object named Account Locations. I want to fetch fields from this related list so I can show them in Google Maps as markers. This works for Contacts but for my custom object Account Locations this ain't working.
This is the controller:
public class AccountLocations { public Account AccountInformation {get; set;} public List<Account_Location__c> AllAccounts {get; set;} public AccountLocations(ApexPages.StandardController controller) { AccountInformation = (Account)controller.getRecord(); } public void fetchtAllRelatedAccountLocations(){ AllAccounts = [ SELECT Id, Location_Name__c, Location_Street__c, Location_Postal_Code__c, Location_City__c, Location_Country__c FROM Account_Location__c WHERE Id = :AccountInformation.Id ]; } }
Hope someone has a solution or idea for this.
Kind regards!
- Rachid El Kaddouri
- July 01, 2014
- Like
- 0
error: too many query rows 50001
I'm having this problem that I can't solve. I tried everything but I can't find a solution. I hope someone can help me out here.
Problem description:
I'm getting this error: Too many query rows: 50001. This is because the functionality will insert up to 50000 records.
The functionality works fine but Salesforce gives me this error because Salesforce thinks its wrong.
How can i prevent this error? Some sources told me that batch apex should work but I didn't succeed in implementing this. Didn't really understood how that works.
Hope someone can help me.
Below you can find the full code:
public class Create_Project_SO { string ProjectID = ApexPages.currentPage().getParameters().get('id'); list<PBSI__PBSI_Sales_Order_Line__c> NewSOLines = new List<PBSI__PBSI_Sales_Order_Line__c>(); list<PBSI__PBSI_Sales_Order__c> NewSOs = new List<PBSI__PBSI_Sales_Order__c>(); integer Amount_DifferentItems = 0; list<integer> Amount_ProjectItem = new list<integer>(); list<string> Id_ProjectItem = new list<string>(); public void Fill_Item_Ids(){ Id_ProjectItem = new list<string>(); list<TOA_fs_Project__c> ProjectLine = [SELECT id, Project_Item_ID_1__c, Project_Item_ID_2__c, Project_Item_ID_3__c, Project_Item_ID_4__c, Project_Item_ID_5__c, Project_Item_ID_6__c, Project_Item_ID_7__c, Project_Item_ID_8__c, Project_Item_ID_9__c, Project_Item_ID_10__c FROM TOA_fs_Project__c WHERE Id =:ProjectID]; for( TOA_fs_Project__c a: ProjectLine){ Id_ProjectItem.add(a.Project_Item_ID_1__c); Id_ProjectItem.add(a.Project_Item_ID_2__c); Id_ProjectItem.add(a.Project_Item_ID_3__c); Id_ProjectItem.add(a.Project_Item_ID_4__c); Id_ProjectItem.add(a.Project_Item_ID_5__c); Id_ProjectItem.add(a.Project_Item_ID_6__c); Id_ProjectItem.add(a.Project_Item_ID_7__c); Id_ProjectItem.add(a.Project_Item_ID_8__c); Id_ProjectItem.add(a.Project_Item_ID_9__c); Id_ProjectItem.add(a.Project_Item_ID_10__c); } } public void Check_Amount_Items(){ Amount_DifferentItems = 0; if(Id_ProjectItem[0]!= null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[1] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[2] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[3] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[4] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[5] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[6] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[7] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[8] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[9] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } } public String ProjectLink{ get{ String ProjectLink = URL.getSalesforceBaseUrl().toExternalForm() +'/'+ ProjectID; return ProjectLink; } } public list<AggregateResult> GroupBy_Project_Locations{ get{ list<AggregateResult> OneOffPlanningLines = [SELECT SUM(Aantal_Item_1__c) Totaal_Item1, SUM(Aantal_Item_2__c) Totaal_Item2, SUM(Aantal_Item_3__c) Totaal_Item3, SUM(Aantal_Item_4__c) Totaal_Item4, SUM(Aantal_Item_5__c) Totaal_Item5, SUM(Aantal_Item_6__c) Totaal_Item6, SUM(Aantal_Item_7__c) Totaal_Item7, SUM(Aantal_Item_8__c) Totaal_Item8, SUM(Aantal_Item_9__c) Totaal_Item9, SUM(Aantal_Item_10__c) Totaal_Item10, Account_Location_ID__c FROM VG_One_Off_Planning__c WHERE Project__c =: ProjectID AND Project_Location__c != null AND Totale_Aantallen_Items__c != 0 GROUP BY Account_Location_ID__c]; return OneOffPlanningLines; } } public list<AggregateResult> Total_Items{ get{ list<AggregateResult> OneOffPlanningLines = [SELECT SUM(Aantal_Item_1__c) Totaal_Item1, SUM(Aantal_Item_2__c) Totaal_Item2, SUM(Aantal_Item_3__c) Totaal_Item3, SUM(Aantal_Item_4__c) Totaal_Item4, SUM(Aantal_Item_5__c) Totaal_Item5, SUM(Aantal_Item_6__c) Totaal_Item6, SUM(Aantal_Item_7__c) Totaal_Item7, SUM(Aantal_Item_8__c) Totaal_Item8, SUM(Aantal_Item_9__c) Totaal_Item9, SUM(Aantal_Item_10__c) Totaal_Item10 FROM VG_One_Off_Planning__c WHERE Project__c =: ProjectID GROUP BY Project__c]; return OneOffPlanningLines; } } Public string Get_WO(){ TOA_fs_Project__c Project = [SELECT VG_Work_Order__c FROM TOA_fs_Project__c WHERE id =: ProjectID]; string WO_ID = string.valueof(Project.VG_Work_Order__c); Return WO_ID; } Public string Get_Main_Acc(){ TOA_fs_Project__c Project = [SELECT VG_Work_Order__c FROM TOA_fs_Project__c WHERE id =: ProjectID]; string WO_ID = string.valueof(Project.VG_Work_Order__c); VG_Work_Order__c VGWO = [SELECT Sales_Order__c FROM VG_Work_Order__c WHERE id =: WO_ID]; string SO_ID = string.valueof(VGWO.Sales_Order__c); VG_Sales_Order__c VGSO = [SELECT Account__c FROM VG_Sales_Order__c WHERE id =: SO_ID]; string Acc_ID = string.valueof(VGSO.Account__c); return Acc_ID; } Public string Get_Account(string ProjectLocationID){ TOA_fs_Project_Location__c ProjectLocation = [SELECT Account_Location__c FROM TOA_fs_Project_Location__c WHERE id =: ProjectLocationID]; string AL_ID = string.valueof(ProjectLocation.Account_Location__c); Account_Location__c AccountLocation = [SELECT Main_Account__c FROM Account_Location__c WHERE id =: AL_ID]; string Account_ID = string.valueof(AccountLocation.Main_Account__c); return Account_ID; } Public string Get_AL(string ProjectLocationID){ TOA_fs_Project_Location__c ProjectLocation = [SELECT Account_Location__c FROM TOA_fs_Project_Location__c WHERE id =: ProjectLocationID]; string AL_ID = string.valueof(ProjectLocation.Account_Location__c); return AL_ID; } public void CreateSOLocations(){ Fill_Item_Ids(); Check_Amount_Items(); String VGWO_ID = Get_WO(); String Customer_Account = Get_Main_Acc(); for(AggregateResult a: GroupBy_Project_Locations){ PBSI__PBSI_Sales_Order__c NewRecord = new PBSI__PBSI_Sales_Order__c(); id myid = string.valueof(a.get('Account_Location_ID__c')); /// system.debug('Blabla ' + myid); NewRecord.Account_Location__c = myid; NewRecord.PBSI__Customer__c = Customer_Account; NewRecord.VG_Work_Order__c = VGWO_ID; NewRecord.Project__c = ProjectID; NewSOs.add(NewRecord); } Insert NewSOs; integer i = 0; integer batchlimit = 0; for(AggregateResult a: GroupBy_Project_Locations){ Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item1'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item2'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item3'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item4'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item5'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item6'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item7'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item8'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item9'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item10'))); for(Integer c = 0; c < Amount_DifferentItems ;c++ ){ PBSI__PBSI_Sales_Order_Line__c NewSOLine = new PBSI__PBSI_Sales_Order_Line__c(); NewSOLine.PBSI__Sales_Order__c = NewSOs[i].id; NewSOLine.PBSI__Item__c = Id_ProjectItem[c]; NewSOLine.PBSI__Quantity_Needed__c = Amount_ProjectItem[c]; if(NewSOLine.PBSI__Quantity_Needed__c != NULL){ NewSOLines.add(NewSOLine); } } i++; batchlimit++; Amount_ProjectItem.clear(); /*if(batchlimit == 80){ batchlimit = 0; Insert NewSOLines; NewSOLines.clear(); }*/ } Insert NewSOLines; } Public list<CreateSo_ItemObject> Shipment_Item_Overview{ get{ Fill_Item_Ids(); Check_Amount_Items(); for(AggregateResult a: Total_Items){ Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item1'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item2'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item3'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item4'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item5'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item6'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item7'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item8'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item9'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item10'))); } list<CreateSo_ItemObject> ProjectItems = new List<CreateSo_ItemObject>(); for(integer i = 0; i < Amount_DifferentItems ;i++ ){ if(Id_ProjectItem[i] != NULL){ PBSI__PBSI_Item__c CurrentItem = [SELECT PBSI__Minimum_On_Hand__c, PBSI__Available_to_Promise__c, Name, PBSI__description__c FROM PBSI__PBSI_Item__c WHERE id =: Id_ProjectItem[i]]; CreateSo_ItemObject item = new CreateSo_ItemObject(); item.Name = CurrentItem.name; item.Description = CurrentItem.PBSI__description__c; item.Quantity = integer.valueof(CurrentItem.PBSI__Available_to_Promise__c); item.QuantityOrdered = Amount_ProjectItem[i]; item.QuantityLeft = integer.valueof(CurrentItem.PBSI__Available_to_Promise__c) - Amount_ProjectItem[i]; if(item.QuantityLeft >= 0){ if(CurrentItem.PBSI__Minimum_On_Hand__c != null){ if(item.QuantityLeft < CurrentItem.PBSI__Minimum_On_Hand__c){ item.LineColor = 'Orange'; }else{ item.LineColor = 'Green'; } }else{ item.LineColor = 'Green'; } }else{ item.LineColor = 'Red'; } ProjectItems.add(item); } } Amount_ProjectItem.clear(); Return ProjectItems; } } }
I hope someone can help me out because I'm stuck at this point.
Kind regards
- Rachid El Kaddouri
- July 01, 2014
- Like
- 0
Trigger to get download link/url from attachments in salesforce?
Hi,
I'm trying to write a trigger that will give me the URL to an attachment on a custom object.
I made a formula text field on a custom object with this formula:
HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank')
But the second step is difficult and I can't seem to get it to work. I want a link of the attachment to display. I want to create a after insert trigger but I can't get it to work.. I hope someone knows a solution for this..
Kind regards
- Rachid El Kaddouri
- May 12, 2014
- Like
- 0
How to prepopulate a Lookup field in VisualForce page?
I'm a little bit stuck at a point to prepopulate a Name from the Contact Object into a Custom Object. Situation: I have a VF page that I use to create new records, I replaced the SF standard NEW button with a custom VF page. In this VF Page there is a LookUp to the Contacts Object but I don't want Users to select the contact from the LookUp. Instead I want to auto-populate the User Name in the Contact field.
I searched for answers but I couldn't find anything. Hope somebody can help me! Below you can find the code snippet of the controller:
public class CreateMultipleVGAvailability{ public String VGAvailabilityLink{ get{ String VGAvailabilityLink = URL.getSalesforceBaseUrl().toExternalForm() + '/a3R/o' ; return VGAvailabilityLink; } } public VG_Availability__c MasterAvailability; public CreateMultipleVGAvailability(ApexPages.StandardController stdController) { this.MasterAvailability = (VG_Availability__c)stdController.getRecord(); } public void CreateVGAvailabilities(){ List<VG_Availability__c> NewAvailabilities = new list<VG_Availability__c>(); String DifferentDates = Apexpages.currentPage().getParameters().get('dates'); String Message; String ContactDateCombination; List<String> Dates = DifferentDates.split(', '); for(String D: Dates){ Date myDate = date.parse(D); VG_Availability__c NewRecord = new VG_Availability__c(); NewRecord.contact__c = MasterAvailability.contact__c; NewRecord.Is_Available__c = MasterAvailability.Is_Available__c; NewRecord.Comments__c = MasterAvailability.Comments__c; NewRecord.Date__c = myDate; ContactDateCombination = string.valueof(NewRecord.contact__c) + string.valueof(myDate); AggregateResult[] ContactDateCombinationAmount = [SELECT count(Id) Amount FROM VG_Availability__c WHERE ContactDateCombination__c =: ContactDateCombination]; if( ContactDateCombinationAmount[0].get('Amount') != 1){ NewAvailabilities.add(Newrecord); }else{ if(Message == Null){ Message = myDate + ', '; }else{ Message = Message + myDate + ', '; } } } if(Message != Null){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.'); ApexPages.addMessage(myMsg); } Insert(NewAvailabilities); } }
- Rachid El Kaddouri
- September 09, 2014
- Like
- 0
apex class fetch data from related list from Custom Object
I'm stuck at this one. I'm trying to fetch fields from a related list but this ain't working for a custom object. This is my situation:
The Object Account has a related list that links to a child Custom Object named Account Locations. I want to fetch fields from this related list so I can show them in Google Maps as markers. This works for Contacts but for my custom object Account Locations this ain't working.
This is the controller:
public class AccountLocations { public Account AccountInformation {get; set;} public List<Account_Location__c> AllAccounts {get; set;} public AccountLocations(ApexPages.StandardController controller) { AccountInformation = (Account)controller.getRecord(); } public void fetchtAllRelatedAccountLocations(){ AllAccounts = [ SELECT Id, Location_Name__c, Location_Street__c, Location_Postal_Code__c, Location_City__c, Location_Country__c FROM Account_Location__c WHERE Id = :AccountInformation.Id ]; } }
Hope someone has a solution or idea for this.
Kind regards!
- Rachid El Kaddouri
- July 01, 2014
- Like
- 0
error: too many query rows 50001
I'm having this problem that I can't solve. I tried everything but I can't find a solution. I hope someone can help me out here.
Problem description:
I'm getting this error: Too many query rows: 50001. This is because the functionality will insert up to 50000 records.
The functionality works fine but Salesforce gives me this error because Salesforce thinks its wrong.
How can i prevent this error? Some sources told me that batch apex should work but I didn't succeed in implementing this. Didn't really understood how that works.
Hope someone can help me.
Below you can find the full code:
public class Create_Project_SO { string ProjectID = ApexPages.currentPage().getParameters().get('id'); list<PBSI__PBSI_Sales_Order_Line__c> NewSOLines = new List<PBSI__PBSI_Sales_Order_Line__c>(); list<PBSI__PBSI_Sales_Order__c> NewSOs = new List<PBSI__PBSI_Sales_Order__c>(); integer Amount_DifferentItems = 0; list<integer> Amount_ProjectItem = new list<integer>(); list<string> Id_ProjectItem = new list<string>(); public void Fill_Item_Ids(){ Id_ProjectItem = new list<string>(); list<TOA_fs_Project__c> ProjectLine = [SELECT id, Project_Item_ID_1__c, Project_Item_ID_2__c, Project_Item_ID_3__c, Project_Item_ID_4__c, Project_Item_ID_5__c, Project_Item_ID_6__c, Project_Item_ID_7__c, Project_Item_ID_8__c, Project_Item_ID_9__c, Project_Item_ID_10__c FROM TOA_fs_Project__c WHERE Id =:ProjectID]; for( TOA_fs_Project__c a: ProjectLine){ Id_ProjectItem.add(a.Project_Item_ID_1__c); Id_ProjectItem.add(a.Project_Item_ID_2__c); Id_ProjectItem.add(a.Project_Item_ID_3__c); Id_ProjectItem.add(a.Project_Item_ID_4__c); Id_ProjectItem.add(a.Project_Item_ID_5__c); Id_ProjectItem.add(a.Project_Item_ID_6__c); Id_ProjectItem.add(a.Project_Item_ID_7__c); Id_ProjectItem.add(a.Project_Item_ID_8__c); Id_ProjectItem.add(a.Project_Item_ID_9__c); Id_ProjectItem.add(a.Project_Item_ID_10__c); } } public void Check_Amount_Items(){ Amount_DifferentItems = 0; if(Id_ProjectItem[0]!= null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[1] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[2] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[3] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[4] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[5] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[6] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[7] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[8] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } if(Id_ProjectItem[9] != null){ Amount_DifferentItems = Amount_DifferentItems + 1; } } public String ProjectLink{ get{ String ProjectLink = URL.getSalesforceBaseUrl().toExternalForm() +'/'+ ProjectID; return ProjectLink; } } public list<AggregateResult> GroupBy_Project_Locations{ get{ list<AggregateResult> OneOffPlanningLines = [SELECT SUM(Aantal_Item_1__c) Totaal_Item1, SUM(Aantal_Item_2__c) Totaal_Item2, SUM(Aantal_Item_3__c) Totaal_Item3, SUM(Aantal_Item_4__c) Totaal_Item4, SUM(Aantal_Item_5__c) Totaal_Item5, SUM(Aantal_Item_6__c) Totaal_Item6, SUM(Aantal_Item_7__c) Totaal_Item7, SUM(Aantal_Item_8__c) Totaal_Item8, SUM(Aantal_Item_9__c) Totaal_Item9, SUM(Aantal_Item_10__c) Totaal_Item10, Account_Location_ID__c FROM VG_One_Off_Planning__c WHERE Project__c =: ProjectID AND Project_Location__c != null AND Totale_Aantallen_Items__c != 0 GROUP BY Account_Location_ID__c]; return OneOffPlanningLines; } } public list<AggregateResult> Total_Items{ get{ list<AggregateResult> OneOffPlanningLines = [SELECT SUM(Aantal_Item_1__c) Totaal_Item1, SUM(Aantal_Item_2__c) Totaal_Item2, SUM(Aantal_Item_3__c) Totaal_Item3, SUM(Aantal_Item_4__c) Totaal_Item4, SUM(Aantal_Item_5__c) Totaal_Item5, SUM(Aantal_Item_6__c) Totaal_Item6, SUM(Aantal_Item_7__c) Totaal_Item7, SUM(Aantal_Item_8__c) Totaal_Item8, SUM(Aantal_Item_9__c) Totaal_Item9, SUM(Aantal_Item_10__c) Totaal_Item10 FROM VG_One_Off_Planning__c WHERE Project__c =: ProjectID GROUP BY Project__c]; return OneOffPlanningLines; } } Public string Get_WO(){ TOA_fs_Project__c Project = [SELECT VG_Work_Order__c FROM TOA_fs_Project__c WHERE id =: ProjectID]; string WO_ID = string.valueof(Project.VG_Work_Order__c); Return WO_ID; } Public string Get_Main_Acc(){ TOA_fs_Project__c Project = [SELECT VG_Work_Order__c FROM TOA_fs_Project__c WHERE id =: ProjectID]; string WO_ID = string.valueof(Project.VG_Work_Order__c); VG_Work_Order__c VGWO = [SELECT Sales_Order__c FROM VG_Work_Order__c WHERE id =: WO_ID]; string SO_ID = string.valueof(VGWO.Sales_Order__c); VG_Sales_Order__c VGSO = [SELECT Account__c FROM VG_Sales_Order__c WHERE id =: SO_ID]; string Acc_ID = string.valueof(VGSO.Account__c); return Acc_ID; } Public string Get_Account(string ProjectLocationID){ TOA_fs_Project_Location__c ProjectLocation = [SELECT Account_Location__c FROM TOA_fs_Project_Location__c WHERE id =: ProjectLocationID]; string AL_ID = string.valueof(ProjectLocation.Account_Location__c); Account_Location__c AccountLocation = [SELECT Main_Account__c FROM Account_Location__c WHERE id =: AL_ID]; string Account_ID = string.valueof(AccountLocation.Main_Account__c); return Account_ID; } Public string Get_AL(string ProjectLocationID){ TOA_fs_Project_Location__c ProjectLocation = [SELECT Account_Location__c FROM TOA_fs_Project_Location__c WHERE id =: ProjectLocationID]; string AL_ID = string.valueof(ProjectLocation.Account_Location__c); return AL_ID; } public void CreateSOLocations(){ Fill_Item_Ids(); Check_Amount_Items(); String VGWO_ID = Get_WO(); String Customer_Account = Get_Main_Acc(); for(AggregateResult a: GroupBy_Project_Locations){ PBSI__PBSI_Sales_Order__c NewRecord = new PBSI__PBSI_Sales_Order__c(); id myid = string.valueof(a.get('Account_Location_ID__c')); /// system.debug('Blabla ' + myid); NewRecord.Account_Location__c = myid; NewRecord.PBSI__Customer__c = Customer_Account; NewRecord.VG_Work_Order__c = VGWO_ID; NewRecord.Project__c = ProjectID; NewSOs.add(NewRecord); } Insert NewSOs; integer i = 0; integer batchlimit = 0; for(AggregateResult a: GroupBy_Project_Locations){ Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item1'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item2'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item3'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item4'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item5'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item6'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item7'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item8'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item9'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item10'))); for(Integer c = 0; c < Amount_DifferentItems ;c++ ){ PBSI__PBSI_Sales_Order_Line__c NewSOLine = new PBSI__PBSI_Sales_Order_Line__c(); NewSOLine.PBSI__Sales_Order__c = NewSOs[i].id; NewSOLine.PBSI__Item__c = Id_ProjectItem[c]; NewSOLine.PBSI__Quantity_Needed__c = Amount_ProjectItem[c]; if(NewSOLine.PBSI__Quantity_Needed__c != NULL){ NewSOLines.add(NewSOLine); } } i++; batchlimit++; Amount_ProjectItem.clear(); /*if(batchlimit == 80){ batchlimit = 0; Insert NewSOLines; NewSOLines.clear(); }*/ } Insert NewSOLines; } Public list<CreateSo_ItemObject> Shipment_Item_Overview{ get{ Fill_Item_Ids(); Check_Amount_Items(); for(AggregateResult a: Total_Items){ Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item1'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item2'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item3'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item4'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item5'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item6'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item7'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item8'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item9'))); Amount_ProjectItem.add(integer.valueof(a.get('Totaal_Item10'))); } list<CreateSo_ItemObject> ProjectItems = new List<CreateSo_ItemObject>(); for(integer i = 0; i < Amount_DifferentItems ;i++ ){ if(Id_ProjectItem[i] != NULL){ PBSI__PBSI_Item__c CurrentItem = [SELECT PBSI__Minimum_On_Hand__c, PBSI__Available_to_Promise__c, Name, PBSI__description__c FROM PBSI__PBSI_Item__c WHERE id =: Id_ProjectItem[i]]; CreateSo_ItemObject item = new CreateSo_ItemObject(); item.Name = CurrentItem.name; item.Description = CurrentItem.PBSI__description__c; item.Quantity = integer.valueof(CurrentItem.PBSI__Available_to_Promise__c); item.QuantityOrdered = Amount_ProjectItem[i]; item.QuantityLeft = integer.valueof(CurrentItem.PBSI__Available_to_Promise__c) - Amount_ProjectItem[i]; if(item.QuantityLeft >= 0){ if(CurrentItem.PBSI__Minimum_On_Hand__c != null){ if(item.QuantityLeft < CurrentItem.PBSI__Minimum_On_Hand__c){ item.LineColor = 'Orange'; }else{ item.LineColor = 'Green'; } }else{ item.LineColor = 'Green'; } }else{ item.LineColor = 'Red'; } ProjectItems.add(item); } } Amount_ProjectItem.clear(); Return ProjectItems; } } }
I hope someone can help me out because I'm stuck at this point.
Kind regards
- Rachid El Kaddouri
- July 01, 2014
- Like
- 0
Trigger to get download link/url from attachments in salesforce?
Hi,
I'm trying to write a trigger that will give me the URL to an attachment on a custom object.
I made a formula text field on a custom object with this formula:
HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank')
But the second step is difficult and I can't seem to get it to work. I want a link of the attachment to display. I want to create a after insert trigger but I can't get it to work.. I hope someone knows a solution for this..
Kind regards
- Rachid El Kaddouri
- May 12, 2014
- Like
- 0
can i get record attachment content in to major record
Hi,
I have a custom object which has attachments.
I want to take the recent attachment and copy that link on to my record (custom field).
How can i do that??
- sami ami
- November 11, 2013
- Like
- 0