You need to sign in to do that
Don't have an account?
Emmanuel Corona
compare two related list from one object
greetings!
Is possible to compare to related list from the opp fi they are made with lookup fields? and if the result is false then reject the save or send a message to the user that the values are not the same?
Thank you"!!
Something like if the value exists in the lookup then reject ?
Let me put this way...
In the opp i have a related list for a custom object called SLA and other to the custom object Buildings... so when the user click on NEW SLA the building related list copy to that new sla or let the user add buildings and then compare that buildings list from SLA with the opp building list, if they are not the same, then reject the creation of the new SLA.
Is that possible?
What I understand that.
There are two child objects SLA and Building. After the new thing am completely lost. :(
In the opp page i have to related list one for SLA and other for buildings.
When the user click on new sla i need to copy the related list (building) to that new request... or if that is not possible, then when the user click on new sla request, add buildings using another related list and then compare the new sla request building related list with the building related list in the opp and if are not the same then reject the creation or do something that don't let add that new sla request to the opp
Create a trigger for when you create a new SLA and then in the trigger, query all the Buildings for the matching the selecting buildings to the list of buildings then reject with an error if it doesn't match.
Is there any relation ship between SLA and Building ?
What I feel like it can be done using VF page and Controller or even using a Trigger
Okay, create a trigger for SLA. When a new SLA is created, automatically create a relationship between SLA and all Buildings that is related to the Opps.
refer to this as guide.
http://www.salesforce.com/us/developer/docs/apexcode/index.htm
On the SLA Request page i have another related list to add buildings... in my case the SLA apply depending on the building classification
I think there's an Opportunity record with SLAs related to it and Buildings related to it.
They want it so that when you create a new SLA, all Buildings related to the same Opportunity will be related to the SLA.
As Val Valino Said
You need to create a trigger on SLA and whenever a new record is inserted.
Query all the Building related to the Currentt Opportunity and Clone/Update them with the New SLA Id.
It seems like it will be a After trigger
Here is something to get you started.
I tried to change the code as:
trigger myTrigger on SLAyEdif__c(after insert){
if(trigger.isInsert){
List<SLAyEdif__c> slaList = new List<SLAyEdif__c>();
Set<ID> oppID = new Set<ID>();
for(SLAyEdif__c s: trigger.New){
If(oppID.contains(s.Opp) == false){
oppID.add(s.Opp);
}
slaList.add(s);
}
Map<string, List<edificio__c>> oppBuildMap = new Map<string, List<edificio__c>>();
for(edificio__c b:[select name, Clasificacion_comercial__c from edificio__c where Opp IN : oppID]){
if(oppBuildMap.get(b.oppID) == false){
List<edificio__c> bList = new List<edificio__c>();
bList.add(b);
oppBuildMap.put(b.oppID, b);
}else{
oppBuildMap.get(b.oppId).add(b);
}
}
List<SLAyEdif__c> updateSLAList = new List<SLAyEdif__c>();
for(SLAyEdif__c s: slaList){
integer x;
for(slaList = 0; x < oppBuildMap.get(s.Opp).size(); x++){
// here add the logic to create new relationships between SLA and Building (I am thinking you are using a junction object?)
updateSLAList.add(s);
}
}
update updateSLAList;
}
}
But i get Error: Error de compilación: Invalid field Opp for SObject SLAyEdif__c en la línea 10 columna 27